使用cURL获取页面 | #basic invocation将输出写入到指定的文件 curl -o example.html http://www.example.com/ #fetch a secure web page通过SSL/TLS获取页面时忽略它不能验证SSL证书 curl -k -o example-secure.html https://www.example.com/ #fetch a file by FTP have curl automatically pick the output filename将下载的文件保存到file.zip中 curl -O ftp://ftp.example.com/pub/download/file.zip | ||
获取URL的许多变体 | #fetch all the categories from 00 to 99 curl -o 'category-#1#2.html' 'http://www.example.com/category.php?CATID=[0-9][0-9]' curl -o 'category-#1.html' 'http://www.example.com/category.php?CATID=[0-99]' #fetch several main pages and store them in files named accordingly curl -o '#1.html' 'http://www.example.com/{news,blog,careers,contact,sitemap}/' curl -o '#1-#2-#3-#4.html'/ "http://www.example.com/cgi0bin/item.cgi?prod=[0001-9999]&cat=[0-9]&color={red,yellow,blue,green}&size={s,m,l,xl}" | ||
自动跟踪重定向 | curl -L -e ';auto' -o 'output.html' 'http://www.example.com/login.jsp' -L选项告诉cURL跟踪重定向响应。-e ';auto'告诉它在跟踪重定向响应时传送Referer头信息 | ||
使用cURL检查跨站式脚本 |
| ||
使用cURL检查目录遍历 |
| ||
冒充特定类型的网页浏览器或设备
| curl -o MSIE.html -A 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;SLCC1; .NET CLR 2.0.50727;Media Center PC 5.0; .NET CLR 3.0.04506)' http://www.example.com/ | ||
curl -o FFMac.html -A 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X;en-US; rv:1.8.1.3)Gecko/20070309 Firefox/2.0.0.15' http://www.example.com/ | |||
curl -o Palm.html -A 'Mozilla/4.0(compatible; MSIE 6.0; Windows 98; PalmSource/hspr-H102; Blazer/4.0)16; 320x320' http://www.example.com/ User-Agent大多数web应用根本不会对浏览器做出反应,但许多使用css,ajax的站点和应用会根据浏览器的不同类型以不同的方式加载到浏览器中 | |||
以交互方式冒充另一种设备 |
User Agent Switcher的firefox扩展 http://www.useragentstring.com/pages/useragentstring.php
| ||
使用cURL模仿搜索引擎 | #fetch as Google,Get the article content curl -o curl-google.html -A / 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' / http://www.linux-mag.com/id/744/ 需要这样获取页面并确保没有机密信息被泄露给搜索引擎 http://www.linux-mag.com/id/744/服务器使用user-agent字符串来区分google和普通浏览器,google将自己标记为“Googlebot”。该服务器保存对google和yahoo这类搜索引擎的可见性,但是要求普通用户在付费或注册后才能查看其内容 | ||
通过假造referer头信息来伪造工作流程 | #Fetch login page curl -o login.php http://www.example.com/login.php #Fetch reports page, with login page as Referer curl -o reports.php -e http://www.example.com/login.php http://www.example.com/reports.php | ||
仅获取HTTP头 | curl -I http://www.amazon.com/ curl -I http://www.mastercard.com/ curl -I http://wwwimages.adobe.com/www.adobe.com/swf/homepage/fma_shell/FMA.swf | ||
使用cURL发送POST请求 | curl -o output.html -d "userid=root" -d "passwd=fluffy" / -d "submit=Login" http://www.example.com/servlet/login.do
<form action="http://www.example.com/servlet/login.do method="POST"> <p>User Name:<input type="text" name="userid"></P> <p>Password:<input type="text" name="passwd"></P> <p><input type="submit" value="Login"></p> </form> 对curl使用-d选项暗中将方法设置为POST,curl不对数据进行编码
curl -o output.html -d "userid=root" -d "passwd=fluffy" / -d "submit=Login" -d @formstate.txt / http://www.example.com/servlet/login.do 将参数名及取值都存储在文件中。然后,在命令行上,使用@来引用它 | ||
保持会话状态 | #fetch the login page curl -b cookies.txt -c cookies.txt / http://www.example.com/servlets/login.do #post the login request, updating the cookies.txt file as we go curl -b cookies.txt -c cookies.txt / -d userid=admin -d passwd=fluffy / http://www.example.com/servlets/login.do -b选项确定在会话开始时到哪里读取cookie -c选项指出在哪里写入在会话中接收到的cookie
| ||
发送假造的cookie | curl -b session-id-time=abc http://www.amazon.com curl -b session-id-time=-1 http://www.amazon.com
| ||
使用cURL上传文件 | curl -F file='photo1.jpg' -F submit=submit / http://www.example.com/photos/upload.do curl -F file='photo1.jpg;filetype=image/jpg' -F submit=submit /http://www.example.com/photos/upload.do | ||
多级测试用例步骤 | 第一步:启动firefox和TamperData 第二步:访问网站并 执行我们想要模仿的动作,用Adblock Plus扩展阻挡广告 第三步:将所有请求导出xml文件 第四步:找出感兴趣的请求并提取出来 第五步:将感兴趣的请求变成curl命令 | ||
浏览器做的事情 | cURL做的事情 | 对测试准确性的影响 | |
获取网页中引用的图像、CSS以及网站书签图标 | 仅获取你告诉的页面,可以跟踪重定向,但仅限于HTTP重定向(不能是javascript document.location()重定向) | 在测试服务器逻辑时,这些差别通常没有任何影响。如果网页浏览器中出现JavaScript形式的重要计算,那么它们不会出现在cURL模拟中 | |
获取远程脚本资源,并执行客户端脚本 | 获取HTML,但是无法执行其中的任何JavaScript、VBScript或其他客户端指令 | 从cURL看来,在浏览器中执行大量逻辑的站点的外观和工作方式会非常不同。对于模仿对这种站点的请求,cURL可能并不是一种很好的选择 | |
允许单击图像化图像地图 | 将x/y坐标作为参数进行传输 | 如果你的网站有图形化图形地图,则必须确定要作为参数发送的x/y坐标对,以模仿对图像的单击 |
使用cURL实现自动化安全测试
最新推荐文章于 2022-07-11 23:44:49 发布