使用Bash发出POST请求 [英] Using Bash to make a POST request

查看:157
本文介绍了使用Bash发出POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须登录才能配置100个Jetpack.我正在尝试以bash脚本执行此操作,但是我没有运气.我可以连接到wifi没问题,但是我的POST请求没有实现任何事情.有什么建议吗?这是我的github的链接.我有在Burp套件中捕获的内容的副本 https://github.com/Jdelgado89/post_Script

I have a 100 Jetpacks that I have to sign in to configure. I am trying to do it in a bash script but I am having no luck. I can connect to the wifi no problem but my POST request are not achieving anything. Any Advice? Here is link to my github. I have copies of what I captured on Burp suite https://github.com/Jdelgado89/post_Script

TYIA

#!/bin/bash

nmcli device wifi rescan
nmcli device wifi list

echo "What's they last four?"
read last4

echo "What's the Key?"
read key

nmcli device wifi connect Ellipsis\ \Jetpack\ $last4 password $key

echo "{"Command":"SignIn","Password":"$key"}" > sign_on.json
echo "{"CurrentPassword":"$key","NewPassword":"G1l4River4dm1n","SecurityQuestion":"NameOfStreet","SecurityAnswer":"Allison"}" > change_admin.json
echo "{"SSID":"GRTI Jetpack","WiFiPassword":"G1l4River3r","WiFiMode":0,"WiFiAuthentication":6,"WiFiEncription":4,"WiFiChannel":0,"MaxConnectedDevice":8,"PrivacySeparator":false,"WMM":true,"Command":"SetWifiSetting"}" > wifi.json

cat sign_on.json
cat change_admin.json
cat wifi.json

sleep 5
curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @sign_on.json http://192.168.1.1/cgi-bin/sign_in.cgi
sleep 5
curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @change_admin.json http://192.168.1.1/cgi-bin/settings_admin_password.cgi
sleep 5
curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @wifi.json http://192.168.1.1/cgi-bin/settings_admin_password.cgi

推荐答案

这是不正确的:

echo "{"Command":"SignIn","Password":"$key"}" > sign_on.json

双引号并没有直接放在文件中,它们只是终止以前一个双引号开头的shell字符串.这就是写作

The double quotes are not being put literally into the file, they're just terminating the shell string beginning with the previous double quote. So this is writing

{Command:SignIn,Password:keyvalue}

放入文件中,不带双引号.您需要转义嵌套的双引号.

into the file, with no double quotes. You need to escape the nested double quotes.

echo "{\"Command\":\"SignIn\",\"Password\":\"$key\"}" > sign_on.json

但是,最好使用 jq 实用程序,而不要手工格式化JSON.请参见使用jq创建JSON文件.

However, it would be best if you used the jq utility instead of formatting JSON by hand. See Create JSON file using jq.

jq -nc --arg key "$key" '{"Command":"SignIn","Password":$key}' >sign_on.json

这篇关于使用Bash发出POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆