Talking Web(2)

简介: Talking Web(2)

3. python

3.1 http

>>> from requests import *
>>> response = requests.get('http://127.0.0.1:80')
>>> print('响应内容:', response.text)
响应内容: pwn.college{83y0SkoeFfnsdU5YogDOF6JGRZQ.dBzNyMDLwYTM2QzW}

向目标主机端口发送http请求

3.2 http+head

>>> import requests
>>> url = 'http://127.0.0.1'
>>> headers = {'Host': '065616a0aaafbede0381252839ae6d59'}
>>> response = requests.get(url, headers=headers)
'HTTP 状态码:', response.status_code)
print('响应内容:', response.text)
>>> 
>>> print('HTTP 状态码:', response.status_code)
HTTP 状态码: 200
>>> print('响应内容:', response.text)
响应内容: pwn.college{Erb8zgS62nA93VGa5cjg8Lib34g.dNzNyMDLwYTM2QzW}

3.3 http+path

修改这里:url = ‘http://127.0.0.1/ed6e3291b486fa09e2847a67f85d7e5f

3.4 get_URL编码路径

空格转义%20

3.5 get传参(略)

3.6 gets多参传递+URL转义符集合

3.7 post传参

在Python中,你可以使用requests库来发送带有参数的POST请求。以下是一个示例代码:

import requests
url = 'http://127.0.0.1:80'
data = {
    'a': '345f4d16a319a34006dd714c0f24fb7d',
    'para':'value2'
}
response = requests.post(url, data=data)
print(response.text)

在这个示例中:

  • 首先,导入requests库。
  • 指定目标URL为http://example.com/api
  • 创建一个字典data,包含要传递的参数数据。
  • 使用requests.post方法发送POST请求,并传递参数数据。
  • 最后,打印响应内容,可以通过response.text访问。

通过这段代码,你可以使用Python发送带有参数的POST请求。requests库简化了HTTP请求的处理,使得发送POST请求变得更加简单和方便。

3.8 post多参

这里注意 python 使用post传参存在空格,&,#等字符时候不需要转义,直接在表单提交!!!

3.9 JSON请求

要发送带有特定内容类型(‘application/json’)的HTTP POST请求,并且请求主体是一个JSON对象,其中包含一个名为a,值为a2058cfa996ff89a3c9a9ae03f9452b3的键值对,你可以使用Python的requests库。以下是一个示例代码:

import requests
import json
url = 'http://127.0.0.1'
headers = {'Content-Type': 'application/json'}
data = {'a': '0be5c44b1be5edf425e00a78e51c0199'}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)

在这个示例中:

  • 导入requestsjson库。
  • 指定目标URL为http://example.com/api
  • 创建一个字典data,包含要作为JSON对象发送的数据。
  • 定义一个headers字典,指定Content-Type为’application/json’。
  • 使用json.dumps(data)将数据转换为JSON格式。
  • 使用requests.post方法发送带有特定内容类型的POST请求。
  • 最后,打印响应内容,可以通过response.text访问。

通过这段代码,你可以使用Python发送带有特定内容类型和JSON格式主体的HTTP POST请求。

3.10 多个JSON请求

要使用Python发送满足条件的HTTP请求,包括指定Content-Type为application/json,并且发送一个JSON对象作为请求体,可以按照以下方式进行:

import requests
import json
headers = {
    'Content-Type': 'application/json'
}
json_data = {
    "a": "bee420ccb4715a19ef4f2e04da40d1da",
    "b": {
        "c": "d04ec34a",
        "d": ["ca260e25", "94ba15f0 6c8c99e7&d52b82b0#eaafdff8"]
    }
}
response = requests.post('http://127.0.0.1', headers=headers, data=json.dumps(json_data))
print(response.text)

在这段代码中:

  • 我们首先定义了请求头部,指定Content-Type为application/json。
  • 然后定义了符合要求的JSON数据,包括"a"和"b"两个键值对,其中"b"的值是一个嵌套的JSON对象,包含"c"和"d"两个键值对,其中"d"的值是一个包含多个元素的列表。
  • 使用requests库发送了一个POST请求,将JSON数据作为请求体发送到目标URL(这里用’http://example.com’代替实际URL)。
  • 最后打印了响应内容,你可以根据实际情况对响应进行处理。

3.11 目标地址重定向

Python的requests库会自动处理HTTP重定向。当你发送一个HTTP请求时,如果服务器返回的响应状态码是3xx(比如302 Found),并且包含重定向的目标URL在响应头的Location字段中,requests库会自动跟随重定向并发送新的请求到重定向的URL。

默认情况下,requests库会自动处理重定向,直到达到最终的目标URL或达到最大重定向次数(默认为30次)。你可以通过设置allow_redirects=False来禁用自动重定向,或者通过max_redirects参数来设置最大重定向次数。

因此,当你使用requests.get()requests.post()等方法发送HTTP请求时,如果服务器返回重定向响应,requests库会自动处理重定向并返回最终的响应结果。这样简化了处理重定向的过程,让你更方便地与Web服务器进行交互。

忽略python自动重定向时候,常规思路:

根据你的要求,你可以使用Python中的requests库来发送HTTP请求到127.0.0.1的端口80,并获取重定向到flag的HTTP响应。以下是一个示例代码,演示如何使用Python发送HTTP请求并处理重定向:

import requests
url = 'http://127.0.0.1:80'  
response = requests.get(url)
if response.status_code == 302:
    redirect_url = response.headers['Location']
    print(f'Redirected to: {redirect_url}')
    flag_response = requests.get(f"http://127.0.0.1:80{redirect_url}")
    print(flag_response.text)
else:
    print('No redirection occurred.')  # 由于python自动重定向,改行会被打印
    
print(response.text)

在这段代码中,首先我们使用requests.get()方法发送HTTP GET请求到目标URLhttp://127.0.0.1:80,然后检查响应状态码是否为302,如果是302表示发生了重定向。接着我们从响应头中获取重定向的URL,并发送新的HTTP请求到该重定向URL,最后输出flag响应的内容。

3.12 重定向+cookie

requests库自动处理服务器返回的cookie,并添加到下一次http请求。

常规:要在Python中处理Cookie,你可以使用requests库来发送HTTP请求并自动处理Cookie。以下是详细的步骤:

  1. 导入requests库
    在Python脚本中,首先需要导入requests库:
import requests
  1. 发送带有Cookie的HTTP请求
    使用requests库发送HTTP请求时,可以通过cookies参数传递Cookie信息。例如,发送一个带有Cookie的GET请求:
url = 'http://example.com'
cookies = {'cookie_name': 'cookie_value'}
response = requests.get(url, cookies=cookies)
  1. 获取服务器响应
    发送请求后,可以通过response对象获取服务器返回的响应内容。例如,获取响应文本和状态码:
print(response.text)
print(response.status_code)
  1. 处理服务器返回的Cookie
    如果服务器返回了新的Cookie,你可以通过response.cookies来获取并处理这些Cookie。例如,获取服务器返回的所有Cookie:
cookies = response.cookies
for cookie in cookies:
    print(cookie.name, cookie.value)

通过以上步骤,你可以在Python中使用requests库来处理Cookie,发送带有Cookie的HTTP请求,并处理服务器返回的Cookie信息。

3.13 发出多个请求

直接正常发送即可,request库自动处理问题…

目录
相关文章
|
2天前
|
机器学习/深度学习 JSON 移动开发
Talking Web(1)
Talking Web(1)
13 7
|
Web App开发 PHP 开发工具
2018CSTC web2 writeup
全国网络空间安全技术大赛,比赛地址http://cstc.xatu.edu.cn/ 这次和小伙伴参加了线上初赛,再次被吊打,除了签到和这题Web2,连Web1就卡着一直没做出来/(ㄒoㄒ)/~~ 题目地址: http://117.
1513 0
|
Web App开发 网络协议 JavaScript
How Do Web Browsers Work
Have you ever wondered how a browser is capable of displaying visually attractive and interactive web pages? Have you encountered Error 404 or a DNS r.
2824 0
|
SQL Python
Defense against Common Web Attacks
The Internet is a powerful tool that connects us with users from across the globe. However, the might of the Internet has also made it vulnerable to abuse.
2059 0
|
自然语言处理 分布式计算 API
Caching Tutorial for Web Authors and Webmasters
https://www.mnot.net/cache_docs/
745 0
Lie to Me: Bypassing Modern Web Application Firewalls
http://www.slideshare.net/d0znpp/lie-tomephd2013
720 0
Best Practices: Use of Web Application Firewalls
https://www.owasp.org/index.php/Category:OWASP_Best_Practices:_Use_of_Web_Application_Firewalls...
656 0