99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀python妙用之編碼的轉(zhuǎn)換詳解
python妙用之編碼的轉(zhuǎn)換詳解
2017-12-04
收藏

python妙用之編碼的轉(zhuǎn)換詳解

記得剛?cè)腴T那個(gè)時(shí)候,自己處理編碼轉(zhuǎn)換問題往往是“百度:url解碼、base64加密、hex……”,或者是使用一款叫做“小葵多功能轉(zhuǎn)換工具”的軟件,再后來直接上Burpsuite的decoder功能,感覺用的還挺好的。不過,也遇到些問題:在線轉(zhuǎn)換效率低(搜索占去了2/3的時(shí)間)、兩款工具存在一些小問題,比如burp中涉及中文往往顯示亂碼。
直到使用python來作為我日常編碼轉(zhuǎn)換工具……

開啟py轉(zhuǎn)換之旅

url編碼

url編碼是一種瀏覽器用來打包表單輸入的格式.可謂是一名作為web人員最熟悉的一種編碼方式了。  
>>> from urllib import *
>>> quote("union select null,null,null")
'union%20select%20null%2Cnull%2Cnull'
>>> unquote("union%20select%20null%2Cnull%2Cnull")
'union select null,null,null'
>>> urlencode({'x':'2333','y':'666'})
'y=666&x=2333'

Base64

Base64常常用作網(wǎng)頁表單和HTTP傳輸?shù)囊恍﹨?shù),也常用于郵件協(xié)議傳輸用戶信息等。    
>>> import base64
>>> base64.b64encode("admin")
'YWRtaW4='
>>> base64.b64decode('YWRtaW4=')
'admin'

記得有次ctf比賽中考到了base32解密,一般網(wǎng)站不提供在線解密,一時(shí)之間貌似沒有辦法繼續(xù)下去。不過如果你使用python的話會像上邊解密base64一樣簡單,只需要將函數(shù)改變下:    
>>> import base64
>>> base64.b32encode('jjjjj')
'NJVGU2TK'
>>> base64.b32decode('NJVGU2TK')
'jjjjj'

Hex

十六進(jìn)制編碼也是web application中常見的一種編碼方案。作為一名web安全人員,我們心知肚明的是,MySQL注入可以使用hex繞過htmlspecialchars()函數(shù)從而寫入webshell。
比如:    
select 0x3c3f70687020406576616c28245f504f53545b615d293b203f3e into outfile '/web/1.php'

下面是python實(shí)現(xiàn)hex加解密的方法:    
>>> '<?php @eval($_POST[a]); ?>'.encode('hex')
'3c3f70687020406576616c28245f504f53545b615d293b203f3e'
>>>
>>> print '3c3f70687020406576616c28245f504f53545b615d293b203f3e'.decode('hex')
<?php @eval($_POST[a]); ?>
>>>

ASCii

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 '/web/1.php'

使用python將字符串轉(zhuǎn)換ascii很簡單,但是逆轉(zhuǎn)換的話需要需要點(diǎn)小操作:  
>>> map(ord, "<?php phpinfo() ?>")
[60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 32, 63, 62]
 
>>> print chr(112)
p
 
>>> l = [60, 63, 112, 104, 112, 32, 112, 104, 112, 105, 110, 102, 111, 40, 41, 32, 63, 62]
>>> print ''.join(map(chr,l)) #感謝pcat表哥指出的方法
<?php phpinfo() ?>

Md5

md5在web安全界可以說是人盡皆知了,以他的不可逆性,大多數(shù)網(wǎng)站存儲用戶密碼等關(guān)鍵數(shù)據(jù)時(shí)常常使用md5加密。有的時(shí)候我們提交payload需要md5加密,這個(gè)時(shí)候用下面的方法就可以輕松實(shí)現(xiàn)。當(dāng)然解密的話推薦去cmd5。    
>>> from hashlib import md5
>>> m = md5()
>>> m.update('this is a secret')
>>> m.hexdigest()
'7dbbcee180ba4d456e4aa1cfbdad9c7b'
 
>>> m.hexdigest()[8:-8]
'80ba4d456e4aa1cf'
>>>

Unicode轉(zhuǎn)中文

unicode轉(zhuǎn)換中文,很多情況下都能遇到。尤其是在做滲透測試的時(shí)候。用burp的話會存在中文亂碼的問題,在python下實(shí)現(xiàn)非常簡單。    
>>> print u"\u4f60\u9700\u8981\u91cd\u65b0\u767b\u9646"
你需要重新登陸

總結(jié)

python實(shí)際上在實(shí)際使用中非常方便,編碼轉(zhuǎn)換只是其中一個(gè)例子。文中提到的編碼轉(zhuǎn)換皆為筆者日常積累,如果有沒有涉及到的地方,歡迎評論補(bǔ)充。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }