=Start=
缘由:
之前在博客中写过一篇文章「在wget和curl中使用代理」,里面说了如何在wget/curl命令中使用代理进行下载、访问操作;后来又看到一篇文章讲的是如何设置wget在遇到某些IP/域名时不使用代理,自己搭建环境实际测试了一下wget和curl,在此记录一下结论和大体过程,方便其它人参考。
正文:
0.先放结论
- wget上no_proxy这个变量需要是「逗号分隔」(单个IP/域名除外)的「域名 或 具体IP」(不能是CIDR格式的IP段)
另外就只能通过「--no-proxy
」选项来控制所有的域名/IP时都不走代理 - curl上只能通过「
--noproxy
」选项来控制在碰到某些IP/域名时不走代理
NO_PROXY变量测试不成功(不论是将其设置为具体的IP还是将其设置为「*」)
1.如何搭建测试环境?
在服务器A(10.10.41.171)上启动一个Apache服务,在服务器B(10.10.41.203)上搭建一个HTTP代理,在服务器C(10.10.41.170)上使用`wget/curl`命令进行测试。
2.测试过程
在服务器B上搭建的代理列表: 10.10.41.203:8001 10.10.41.203:8002 在服务器A(10.10.41.171)上根据访问日志判断代理是否生效: tail -f /var/log/httpd/access_log 下面记录的都是在服务器C(10.10.41.170)上进行操作: #直接访问 curl -I http://10.10.41.171 #通过代理访问 curl -x 10.10.41.203:8001 -I http://10.10.41.171 #将代理写入环境变量然后测试 export http_proxy="http://10.10.41.203:8001" curl -I http://10.10.41.171 wget http://10.10.41.171 #将非代理列表写入环境变量然后测试wget export no_proxy="10.10.41.171,10.10.41.135" #生效 wget http://10.10.41.171 export no_proxy="10.10.41.171/30" #不生效 wget http://10.10.41.171 wget http://10.10.41.171 --no-proxy #生效 #将非代理列表写入环境变量然后测试curl curl -I http://10.10.41.171 --noproxy "10.10.41.171,10.10.37.135" #生效 curl -I http://10.10.41.171 --noproxy "*" #生效 export NO_PROXY="10.10.41.171,10.10.37.135" #不生效 curl -I http://10.10.41.171 export NO_PROXY="10.10.41.171" #不生效 curl -I http://10.10.41.171 export NO_PROXY="*" #不生效 curl -I http://10.10.41.171
#快速为`no_proxy`变量赋值为网段列表(10.1.1.1/16) printf -v no_proxy '%s,' 10.1.{1..255}.{1..255} export no_proxy="${no_proxy%,}" #或 export no_proxy="$(echo 10.1.{1..255}.{1..255} | tr ' ' ',')"
参考链接:
- http://unix.stackexchange.com/questions/23452/set-a-network-range-in-the-no-proxy-environment-variable
- http://serverfault.com/questions/623543/centos-6-5-proxy-bypass-no-proxy-not-working
- man wget
- man curl
=END=
《 “在wget和curl中「不」使用代理” 》 有 9 条评论
Expect:100-continue
http://www.laruence.com/2011/01/20/1840.html
`
在使用curl做POST的时候,当要POST的数据大于1024字节的时候,curl并不会直接就发起POST请求,而是会分为俩步:
1. 发送一个请求,包含一个 ‘Expect:100-continue’ ,询问Server使用愿意接受数据
2. 接收到Server返回的 ‘100-continue’ 应答以后,才把数据POST给Server
`
https://github.com/openzipkin/docker-zipkin/issues/114
https://curl.haxx.se/mail/archive-2005-06/0074.html
https://stackoverflow.com/questions/14158675/how-can-i-stop-curl-from-using-100-continue
https://stackoverflow.com/questions/2964687/how-to-handle-100-continue-http-message
http://www.cnblogs.com/zhengyun_ustc/p/100continue.html
在渗透中curl的常见用法
https://mp.weixin.qq.com/s/Zz7O81Qt2B8qDAFf4hvvcg
`
常规访问
curl http://www.myh0st.cn
文件名正则
curl ftp://ftp.myh0st.cn/file%5B1-100%5D.txt
curl ftp://ftp.myh0st.cn/file%5B1-100:10%5D.txt
curl ftp://ftp.myh0st.cn/file%5B001-100%5D.txt
curl ftp://ftp.myh0st.cn/file%5Ba-z%5D.txt
curl ftp://ftp.myh0st.cn/file%5Ba-z:2%5D.txt
域名正则
curl http://site.{one,two,three}.com
目录正则
curl http://www.myh0st.cn/archive%5B1996-1999%5D/vol%5B1-4%5D/part{a,b,c}.html
常规下载页面
curl -o index.html http://www.myh0st.cn/
curl http://www.myh0st.cn/ > index.html
添加下载进度条
curl -# http://www.myh0st.cn/ > index.html
使用不同的版本的http协议
默认1.0版本
curl -0 http://www.myh0st.cn
指定版本
curl –http1.1 http://www.myh0st.cn
curl –http2 http://www.myh0st.cn
使用不同的ssl版本访问
tlsv1
curl -1 http://www.myh0st.cn
curl –tlsv1 http://www.myh0st.cn
sslv2
curl -2 http://www.myh0st.cn
curl –sslv2 http://www.myh0st.cn
sslv3
curl -3 http://www.myh0st.cn
curl –sslv3 http://www.myh0st.cn
使用不同的ip协议
ipv4
curl -4 http://www.myh0st.cn
curl –ipv4 http://www.myh0st.cn
ipv6
curl -6 http://www.myh0st.cn
curl –ipv6 http://www.myh0st.cn
指定user-agent
curl -A “wget/1.0” http://www.myh0st.cn
curl –user-agent “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)” http://www.myh0st.cn
curl –user-agent “Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)” http://www.myh0st.cn
指定cookie
curl -b “phpsession=Testtest” http://www.myh0st.cn
curl –cookie “name=Daniel” http://www.myh0st.cn
指定cookie文件
curl -c cookies.txt http://www.myh0st.cn
curl –cookie-jar cookies.txt http://www.myh0st.cn
提交post数据
curl -d “username=admin&password=pass” http://www.myh0st.cn
curl –data “birthyear=1905&press=%20OK%20” http://www.myh0st.cn/when.cgi
curl –data-urlencode “name=I am Daniel” http://curl.haxx.se
curl –data “” –header “Content-Type: text/xml” –request PROPFIND url.com
指定referer
curl -e “http://www.myh0st.cn/referer” http://www.myh0st.cn
curl –referer http://www.myh0st.cn/referer http://www.myh0st.cn
指定header
curl –header “Host:www.myh0st.cn” http://www.myh0st.cn
显示访问网页的header
curl -D – http://www.myh0st.cn
curl –dump-header headers_and_cookies http://www.myh0st.cn
跟随location跳转页面
curl -L http://www.myh0st.cn
curl –location http://www.myh0st.cn
指定dns访问网站
curl –dns-servers 8.8.8.8 http://www.myh0st.cn
指定证书访问https的网页
curl –cert mycert.pem https://www.myh0st.cn
`
经验分享 | 基于代理IP的挖掘与分析
http://www.freebuf.com/articles/web/159172.html
如何让 curl 命令通过代理访问
https://mp.weixin.qq.com/s/rXklr52ElJFCtriSAt41XA
https://www.cyberciti.biz/faq/linux-unix-curl-command-with-proxy-username-password-http-options/
CURL命令忽略https请求的SSL证书
http://www.osetc.com/archives/20522.html
https://curl.haxx.se/docs/sslcerts.html
`
在使用wget命令来获取文件的时候,我们可以使用wget命令的 –no-check-certificate 选项来忽略证书的认证。 那么在执行curl命令是否也可以忽略SSL证书的警告信息呢。
当然是有的,我们可以在执行curl 命令的时候,使用 -k 或者 –insecure 选项,来忽略签名认证的警告。 这样就可以让curl命令执行不安全的SSL连接,进而去获取数据。
命令使用示例如下:
curl -k https://osetc.com
curl –insecure https://osetc.com
–proxy-insecure
–cacert
`
在Linux系统下使用curl自定义HTTP头的方法
https://linux.cn/article-4957-1.html
http://ask.xmodulo.com/custom-http-header-curl.html
`
curl提供了一个简单的方法来完全控制传出HTTP请求的HTTP头。你需要的这个参数是“-H” 或者 “–header”。
为了定义多个HTTP头部字段,”-H”选项可以在curl命令中被多次指定。
不要在”-H”选项里面一次设置多个头部字段!!!
不要在”-H”选项的字段里面添加多余的「单引号/双引号」!!!
$ curl http://localhost:8080/data/ -X POST -H “‘Content-Type’:’application/json’” -d ‘{“id”:3, “type”:”ios”, “data”:”xxxxx”}’ -v
* Trying ::1…
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /data/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> ‘Content-Type’:’application/json’ #这个效果不是我们最初想要的!!!
> Content-Length: 38
> Content-Type: application/x-www-form-urlencoded
>
$ curl http://localhost:8080/data/ -X POST -H “Content-Type: application/json” -d ‘{“id”:3, “type”:”ios”, “data”:”xxxxx”}’ -v
* Trying ::1…
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /data/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 38
>
`
BaseProxy:异步http/https代理
https://mp.weixin.qq.com/s/j3EkBYrMvQdZDl9zALU-Tw
https://github.com/qiyeboy/BaseProxy
`
BaseProxy项目的本意是为了使HTTP/HTTPS拦截更加纯粹,更加易操作,学习成本更低。
异步http/https代理,可拦截并修改报文,能被用于中间人工具,支持py3.5+
`
Windows系统是否有类似于wget/curl这样的内置网络请求命令可以直接用?
windows built-in exe send http post from cmd
Is there a built-in command-line tool under Windows like wget/curl?
https://serverfault.com/questions/483754/is-there-a-built-in-command-line-tool-under-windows-like-wget-curl
`
没有。如果你想实现类似的功能,要么手动下载curl/wget到Windows电脑上,要么使用powershell来实现相关功能。另:win10内置了curl命令可以直接使用。
There is no wget like built-in command in Windows. You can use the .net Framework via Windows PowerShell.
# example 1
Invoke-WebRequest -OutFile index.html -Uri https://superuser.com
# example 2
iwr -outf index.html https://superuser.com
Windows 10 includes curl.exe
`
https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2
https://techcommunity.microsoft.com/t5/containers/tar-and-curl-come-to-windows/ba-p/382409
curl 转换器
https://curlconverter.com/
`
一个将 curl 命令转为 Python、Node.js、R、PHP、Go 代码的在线工具。
Convert curl commands to Python, JavaScript and more
`
Website for converting curl commands to code
https://github.com/curlconverter/curlconverter.github.io/blob/master/index.js