- 论坛徽章:
- 0
|
关于nc的一种使用方法
Nc是一种很强的网络工具,最近发现了它的一种很有用的使用方法,那就是可以在linux命令行进行网页的浏览和用来执行某些自动的网上操作,例如如果网上有一个网页方式的短信平台,而我们又没有接口,我们可以使用nc进行登录并发送定制的短信息。以下是大概方法。
先下一个和Burp proxy类似的代理服务器工具,按正常方式上网发短信,然后会生成一个日志文件,里面有和以下类似的东西:
OrI>GET / HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)
Host: localhost:8000
Connection: Keep-Alive
NeW>HTTP/1.1 302 Moved Temporarily
Location: http://localhost:8000/index.htm
Content-Type: text/plain
Content-Length: 0
Date: Tue, 26 Sep 2006 03:24:38 GMT
Server: Apache Coyote/1.0
其中以OrI>开头的是发送的内容,以NeW>开头的是返回的结果,把以OrI>开头的东东单独拷贝下来(不包括OrI>),可以不拷贝一些取图片的文件,例如
OrI>GET /images/index_log.jpg HTTP/1.1
Accept: */*
Referer: http://localhost:8000/index.htm
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
If-Modified-Since: Mon, 03 Nov 2003 04:42:22 GMT
If-None-Match: W/"27630-1067834542000"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)
Host: localhost:8000
Connection: Keep-Alive
NeW>HTTP/1.1 304 Not Modified
Date: Tue, 26 Sep 2006 03:24:38 GMT
Server: Apache Coyote/1.0
分析整理好的文件(test),看看有没有形如:
JSESSIONID=73E356D861EC5FBF712A1F815BFA4C60的东东,它是网页的sessionid,是动态的,如果要成功的执行某些操作就必需动态的修改sessionid的值,该值可以在nc的返回信息中获取,具体方法如下,在第一个出现sessionid的地方将test文件分成两半,前半部分设为test1,后半部分设为test2,
可以使用以下shell命令
E=`nc ip port -9A-F]\{32\}'`
A='s/JSESSIONID=[0-9A-F]\{32\}/'$E'/g'
sed $A /test2 >/test3
获取新session的值并替换旧session
另外一个需要替换的地方是一些提交信息的内容:
OrI>POST /login2.jsp HTTP/1.1
OrI>Accept: */*
Referer: http://localhost:8000/index.htm
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)
Host: localhost:8000
Content-Length: 93
Connection: Keep-Alive
Cache-Control: no-cache
biglocation=01&smalllocation=&user_id1=####&password=####&login_name=####&user_id=####
其中Content-Length: 93的值是根据“biglocation=01&smalllocation=&user_id1=####&password=####&login_name=####&user_id=####”的长度定的,所以如果提交值的内容变了Content-Length的值也要变。
CONTENT_LENGTH=`cat /test3 | grep biglocation |awk '{print length($0)}'`
eval "sed 's/#CONTENT_LENGTH#/"$CONTENT_LENGTH"/' /test3 >/test4"
最后可以使用
nc ip port /testlog
完成定制的操作。
该方法可以在linux shell中执行一些定制的网页操作,也是测试网站某些功能是否正常的一种方法。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21917/showart_181130.html |
|