Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 25.39 KB | None | 0 0
  1. [quote="QuickStep"][size=25]Socket Authentication[/size]
  2.  
  3. [b]This tutorial can be used for the following ends:[/b][list][*] Logging into sites
  4. [*]Posting information on a site
  5. [*]Getting to pages which can only be accessed if you are logged in.[*]Getting to any page that you basically want, while using mIRC sockets![/list][b]Two examples:[/b]
  6. [list=1][*]Logging into a phpbb forum (like hawkee.com)[*]Posting threads on a phpbb forum[/list][size=18][color=red]Beginner[/color][/size]
  7. [list=1][color=blue]
  8. [*] What information do I have to send in the sockopen event (http)?
  9. [/color][/list]
  10.  
  11. [size=18][color=red]Intermediate[/color][/size]
  12. [list=1][color=blue][*] How can I submit information through a http socket (GET)
  13. [*] How can I submit information through a http socket (POST)?
  14. [*] How do I simulate a website form?
  15. [*] How do I succesfully establish an ssl connection (6.17+)?
  16. [/color][/list]
  17.  
  18. [size=18][color=red]Expert[/color][/size]
  19. [list=1][color=blue][*] How do I log-in to a site (cookies and forms)?
  20. [/color][/list]
  21.  
  22. [size=18][color=red]Usefull Snippets[/color][/size]
  23.  
  24. Before we begin, I'd like to supply you with 2 basic aliases, which will play an important role. One is for removing html code:
  25. [code]alias -l htmlfree {
  26.   var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&,$chr(9))
  27.   return %x
  28. }
  29. [/code][i]Usage: $htmlfree(text)[/i]
  30.  
  31. [code]alias urlencode {
  32.   var %a = $regsubex($$1,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2)))
  33.   return $replace(%a,$chr(32),$chr(43))
  34. }[/code][i]Usage: $urlencode(text)[/i]
  35.  
  36. [size=18][color=red]Intermediate[/color][/size]
  37.  
  38. [b][size=16][color=blue]Q: How can I submit information through a http socket (GET)?[/color][/size][/b]
  39.  
  40. You have probably seen this a lot when using your webbrowser. Submitting information using the GET method is just simply putting a question mark after the url you want to GET and after that seperate each variable name and value with a '&' character.
  41.  
  42. So for example, the following URL sends 5 variables:
  43. http://hawkee.com/phpBB2/viewtopic.php?t=10835&start=0&postdays=0&postorder=asc&highlight=
  44. [b]t[/b] (value: [b]10835[/b])
  45. [b]start[/b] (value: [b]0[/b])
  46. [b]postdays[/b] (value: [b]0[/b])
  47. [b]postorder[/b] (value: [b]asc[/b])
  48. [b]highlight[/b] (value:)
  49.  
  50. These variables can be fetched by the web server, and processed later. This sounds very easy and basic, but there is one important thing you should keep in mind. You have to ALWAYS url-encode the values of the variables when using the GET method, to avoid errors (Do not url-encode the entire string). Refer to the $urlencode snippet at the top of this tutorial.
  51.  
  52. So to conclude, a valid GET request to the server for the url http://hawkee.com/phpBB2/viewtopic.php?t=10835&start=0&postdays=0&postorder=asc&highlight= would be:
  53. [code]on *:SOCKOPEN:hawkee.com:{
  54.   ; Set the variables we want to send:
  55.   var %string = t= $+ $urlencode(10835) $+ &start= $+ $urlencode(0) $+ &postdays= $+ $urlencode(0) $+ &postorder= $+ $urlencode(asc) $+ &highlight=
  56.  
  57.   ; Send GET and Host
  58.   sockwrite -n $sockname GET /phpBB2/viewtopic.php? $+ %string HTTP/1.1
  59.   sockwrite -n $sockname Host: hawkee.com
  60.  
  61.   ; We are done
  62.   sockwrite -n $sockname $crlf
  63. }[/code]
  64.  
  65.  
  66. [b][size=16][color=blue]Q: How can I submit information through a http socket (POST)?[/color][/size][/b]
  67.  
  68. The POST method is almost similar to the GET method. The only difference is that the variables aren't passed in the URL itself, but instead are send at the end of your requests. Other than that a few adjustments have to made when using the POST method:
  69. [list=1][*]POST have to be used in stead of GET
  70. [*]Content headers have to be send
  71. [*]The variables have to be send at the end of your request (don't worry, an example will soon follow).
  72. [/list]
  73. As you already read, the Content headers have to be send. The two extra Content headers are:
  74. [b]Content-Length: <length of sumitted data>[/b]
  75. and
  76. [b]Content-Type: application/x-www-form-urlencoded[/b]
  77.  
  78. The Content-Length tells the server the length of the submitted data and Content-Type tells the server the type of data we are sending (usually url-encoded).
  79.  
  80. So to conclude, a valid POST request to the server for the url http://hawkee.com/phpBB2/viewtopic.php
  81. where we want to POST the following variables t=10835&start=0&postdays=0&postorder=asc&highlight= would be:
  82. [code]on *:SOCKOPEN:hawkee.com:{
  83.   ; Set the variables we want to send:
  84.   var %string = t= $+ $urlencode(10835) $+ &start= $+ $urlencode(0) $+ &postdays= $+ $urlencode(0) $+ &postorder= $+ $urlencode(asc) $+ &highlight=
  85.  
  86.   ; Send POST and Host
  87.   sockwrite -n $sockname POST /phpBB2/viewtopic.php HTTP/1.1
  88.   sockwrite -n $sockname Host: hawkee.com
  89.  
  90.   ; Send the extra content headers
  91.   sockwrite -n $sockname Content-Length: $len(%string)
  92.   sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  93.  
  94.   ; We are done, remember we have to send the %string last
  95.   sockwrite -n $sockname $crlf %string
  96. }[/code]
  97.  
  98.  
  99. [b][size=16][color=blue]Q: How do I simulate a website form?[/color][/size][/b]
  100.  
  101. [i]Note: if you want to log-in, or other actions when submitting a form that requires you to set a cookie, please refer to the [color=red][b]advanced[/b][/color] questions.[/i]
  102.  
  103. This requires you to take a peek into the website source.
  104.  
  105. For this example I will use www.google.com
  106. Maybe you are wondering: why google? Well because google almost includes everything we need to know about simulating forms.
  107. The first thing we have to do is find the <form></form> tags and all the <input> tags between the opening and closing form tags. Remove all the extra html code between the <form> tags.
  108.  
  109. Result for www.google.com:
  110. [code]<form action=/search name=f>
  111.   <input type=hidden name=hl value=nl>
  112.   <input maxlength=2048 size=55 name=q value="" title="Google zoeken">
  113.   <input type=submit value="Google zoeken" name=btnG>
  114.   <input type=submit value="Ik doe een gok" name=btnI>
  115.   <input id=all type=radio name=meta value="" checked>
  116.   <input id=lgr type=radio name=meta value="lr=lang_nl" >
  117.   <input id=cty type=radio name=meta value="cr=countryNL" >
  118. </form>[/code]
  119. Now first of all I will give you the default values for the form and input tags:
  120. [b]For <form>:[/b][list=1][*]If no action is specified, the action defaults to "/" (action="/")
  121. [*]If no method is specified, the method defaults to "GET" (method="GET")
  122. [*]If no name is specified, the name defaults to "" (name="")
  123. [/list][b]For <input>:[/b][list=1][*]A name always HAS to be specified (name="...")
  124. [*]If no type is specified, it defaults to "text" (type="text")
  125. [*]If no value is specified, it defaults to "" (value="")
  126. [/list]
  127. As you can see there are multiple input [b]types[/b], in our example: hidden, submit, text (not specified, default value) and radio
  128.  
  129. The method of the form is GET (not specified, so defaults to GET, see above), the action is "/search". Remember that these 2 values are the only two things you need to retrieve from the <form> tag.
  130. The inputs have to be send like this: name1=value1&name2=value2&name3=value3
  131. Looks familiar huh (see [color=blue][b]Q How can I submit information through a http socket (GET)?[/b][/color]).
  132.  
  133. AW few things to remember:[list=1][*]The value of the hidden inputs (<input type="hidden" name="foo" value="bar">) is just the value that is in the html source. So in the example it would be foo=bar
  134. [*]The value of the submit inputs (<input type="submit" name="foo" type="bar">) is ONLY send if the user clicked THIS particular button. So if the form has multiple submit buttons (like our google example), the name=value is only send for the button the user clicked.
  135. [*]The value for the text inputs (<input type="text" name="foo"> or <input name="foo">) is what the user entered. So if the user entered "barbarbar", the form sends: foo=barbarbar
  136. [*]The value for radio is only send if the user checked the radio button. More or less the same story as the submit button.
  137. [*]The value for checkboxes should be 'on' if checked (<input type="checkbox" name="foo">). This example would send: foo=on if the checkbox is checked. If the checkox is not checked, don't send anything (just like radio buttons, you don't have to send data for the buttons that are not checked).
  138. [/list]
  139.  
  140. So now, with all the knowledge I have shared with you, we will look at our google example and predict what the form will send if we entered the text "foobar" and click the first submit button. We will leave the radio button as is, so we will send the name=value of the radio button which is already checked by default:
  141. The form will send...[list=1][*]hl=nl , from the first hidden input.
  142. [*]q=foobar , from the entered text from the user.
  143. [*]btng=Google+Zoeken , from the submit button we clicked
  144. [*]meta= , from the checked radio button
  145. [/list]And that's it. So the total string will be: "hl=nl&q=foobar&btnG=Google+zoeken&meta=" We will submit the data using the "GET" method and to url: "/search".
  146. All this results in the following page: http://www.google.nl/search?hl=nl&q=foobar&btnG=Google+zoeken&meta=
  147. Remember if we are going to do this with sockets, we have to url encode the string. For the full explanation on how to do the following with sockets, see [color=blue][b]Q How can I submit information through a http socket (GET)?[/b][/color].
  148.  
  149. [b]Conclusion:[/b]
  150. I didn't do this in socket code, but it's all explained in the 2 Q&A above. In the google example the method of the form was GET, but usually the method is POST. So this means you will have to send the string (url-encoded) using the POST method. Again, refer to the [b][color=blue]Q: How can I submit information through a http socket (POST)?[/color][/b]
  151.  
  152.  
  153.  
  154. [b][size=16][color=blue]Q: How do I succesfully establish an ssl connection (6.17+)?[/color][/size][/b]
  155.  
  156. ...
  157.  
  158.  
  159. [size=18][color=red]Expert[/color][/size]
  160.  
  161. [b][size=16][color=blue]Q: How do I log-in to a site (cookies and forms)?[/color][/size][/b]
  162.  
  163. Obviously the method of logging in will be different for every site you visit. That's why I will cover every aspect of the log-in process, ending with a full snippet code where I will log into hawkee and retrieve my mail address.
  164.  
  165. First it is important to cover the complete process off recieving and sending cookies.
  166.  
  167. [b][size=14][color=green]Recieving Cookies[/color][/size][/b]
  168. The server can request the client to store a cookie with the following header:
  169. [b]Set-Cookie: <contents of cookie>[/b]
  170. The contents of a cookie usually follow the following format:
  171. [b]Set-Cookie: name=value; path=/; expires=date;[/b]
  172. Explaination:[list=1][*][b]name=value;[/b] The name of the cookie, and the value it holds. The ';' is NOT part of the value, it just marks the end of the value. The cookie HAS to have a name, the value is optional and defaults to "".
  173. [*][b]path=/;[/b] The remote path where the cookie should be applied to. '/' means for every page on the server, which is also the default value if no path is supplied. '/dir' means for all the pages in '/dir' and 'index.php' means only for 'index.php'. For example if hawkee would send the following cookie:
  174. [code]Set-Cookie: foo=bar; path=/phpBB2; expires=Tuesday, 05-Jun-07 23:16:49 GMT;[/code]It would mean that this cookie has to be send for all pages within www.hawkee.com/phpBB2/
  175. [*][b]expires=date;[/b] Means after what date the client should remove the cookie. If no 'expires' is supplied, it will default to 'after the current session', meaning when the page is left.[/list]
  176. The [b]path[/b] and [b]expires[/b] are usually not very interesting when it comes to scripting.
  177.  
  178. Now that this is covered, there is one important thing to keep in mind. The server can send [b]multiple[/b] cookies. Because of this we can only make sure that we recieved all the cookies after the complete header has been send. To illustrate this, here is an example from hawkee itself, where the server is sending multiple cookies:
  179. [code]HTTP/1.1 302 Found
  180. Date: Mon, 05 Jun 2006 23:16:49 GMT
  181. Server: Apache/1.3.36 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.2 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.27 OpenSSL/0.9.7a
  182. X-Powered-By: PHP/4.4.2
  183. Set-Cookie: PHPSESSID=f4b8fa0a94ced645682b4f6030b21c9a; path=/
  184. Expires: Thu, 19 Nov 1981 08:52:00 GMT
  185. Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  186. Pragma: no-cache
  187. Set-Cookie: phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22; expires=Tuesday, 05-Jun-07 23:16:49 GMT; path=/
  188. Set-Cookie: phpbb2mysql_sid=b1716ad23f970c350daa5941ab8a6f8a; path=/
  189. Set-Cookie: phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A32%3A%221902098234484bb61; expires=Tuesday, 05-Jun-07 23:16:49 GMT; path=/
  190. Set-Cookie: phpbb2mysql_sid=4f3e2ea27ba2115051c1c77fc57e224c; path=/
  191. Location: http://www.hawkee.com/index.php?sid=4f3e2ea27ba2115051c1c77fc57e224c
  192. Connection: close
  193. Transfer-Encoding: chunked
  194. Content-Type: text/html[/code][i]Note: Some headers have been modified to secure my account, and to make it better fit on the page[/i]
  195.  
  196. The server is sending 5 requests to store a cookie. Let's list the names and values here:[list=1][*][b]Name:[/b] PHPSESSID [b]Value:[/b] f4b8fa0a94ced645682b4f6030b21c9a
  197. [*][b]Name:[/b] phpbb2mysql_data [b]Value:[/b] a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22
  198. [*][b]Name:[/b] phpbb2mysql_sid [b]Value:[/b] b1716ad23f970c350daa5941ab8a6f8a
  199. [*][b]Name:[/b] phpbb2mysql_data [b]Value:[/b] a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A32%3A%221902098234484bb61
  200. [*][b]Name:[/b] phpbb2mysql_sid [b]Value:[/b] 4f3e2ea27ba2115051c1c77fc57e224c
  201. [/list]
  202. Now, what you probably already noticed is that the server is sending the same cookie multiple times. This is VERY important to keep in mind, and can make or break your snippet: [b]The value of the cookie that is send LAST should be stored, overwriting any existing values that were previously acquired.[/b]
  203. In our example above, this means that only the last 2 phpbb2mysql_data and phpbb2mysql_sid should be stored, the 2 before that should be removed/overwritten.
  204.  
  205. [b]Conclusion:[/b]
  206. The client should [b]store[/b] the cookie [b]name[/b] and [b]value[/b] for every cookie it recieves, overwriting any previously acquired cookies from the site.
  207.  
  208. [b][size=14][color=green]Sending Cookies[/color][/size][/b]
  209. Now that you have stored the cookie's (in a text file or whatever, I will cover this later in my example where I will log-in into hawkee.com) you have to send them when requesting a new page.
  210.  
  211. This is done by sending the following header:
  212. [b]Cookie: <contents of cookie>;[/b]
  213. So if the client would want to send the cookie named 'foo' with content 'bar', the client would send:[b]Cookie: foo=bar;[/b]
  214.  
  215. But as you've seen above, the user can recieve multiple cookies. If this is the case, you have to seperate each cookie with a ';'.
  216. For example, if the user would have 2 cookies: one named 'foo' with value 'bar' and one named 'test' with value 'bla', the following header should be send:
  217. [b]Cookie: foo=bar; test=bla;[/b]
  218.  
  219. One final, and VERY important notice. The contents of the cookie SHOULD NOT be url-encoded. Just send the contents of the cookie like you RECIEVED it, to avoid conflicts.
  220.  
  221. So an example request to the server would be:
  222. [code]on *:SOCKOPEN:hawkee.com:{
  223.   ; Set the variables we want to send:
  224.   var %string = t= $+ $urlencode(10835) $+ &start= $+ $urlencode(0) $+ &postdays= $+ $urlencode(0) $+ &postorder= $+ $urlencode(asc) $+ &highlight=
  225.  
  226.   ; Send POST and Host
  227.   sockwrite -n $sockname POST /phpBB2/viewtopic.php HTTP/1.1
  228.   sockwrite -n $sockname Host: hawkee.com
  229.  
  230.   ; Send the extra content headers
  231.   sockwrite -n $sockname Content-Length: $len(%string)
  232.   sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  233.  
  234.   ; Send extra cookie data
  235.   sockwrite -n $sockname Cookie: foo=bar; test=bla;
  236.  
  237.   ; We are done, remember we have to send the %string last
  238.   sockwrite -n $sockname $crlf %string
  239. }[/code]
  240.  
  241. [b]Conclusion:[/b]When the client recieves a cookie, it should send it to everytime after every new request (GET or POST, doesn't matter). To send a cookie, you do not have to send multiple cookie headers, only send one while seperating multiple cookies with the ';' characters. Do not url-encode cookies, just send them like you recieved them.
  242.  
  243. [b][size=14][color=green]How to proceed, logging in to a site[/color][/size][/b]
  244. Now that you know everything you need to know about cookies, it's time to proceed to what we actually wanted to do, logging-in to a site. Before proceeding, make sure you've read and understand the following [b][color=red]intermediate[/color][/b] questions:
  245. [b][color=blue]Q How can I submit information through a http socket (POST)?
  246. Q How do I simulate a website form?[/color][/b]
  247.  
  248. Done? Now here how it's done, in basic outline:[list][*]First we will look up the log-in form of the site we want to log-in to. Take a look at where the form submits to, and what information we have to send (obviously username and password, but we do have to send more data to succesfully simulate the form).
  249. [*]When this is done, we will recieve (a/multiple) cookie(s) from the server and we will store these.
  250. [*]We will open a new connection, requesting a page that can only be viewed while we are logged in. While sending the headers, we must include the cookies we recieved earlier.
  251. [*]If all went well, we should be able to see this page[/list]
  252.  
  253. If you've read the Q&A I told you to read and understand, and you something about scripting, you should be able to pull this off. But I know what you really want is a practical example. And I'm going to show you now.
  254.  
  255. [b][size=14][color=green]Practical example: logging in to hawkee.com[/color][/size][/b]
  256. What we would like to do is log-in to your account. The form can be accessed through the main page http://www.hawkee.com here. Then we would like to retrieve the user's email address, which can be found http://hawkee.com/phpBB2/profile.php?mode=editprofile here.
  257.  
  258. [b]The idea:[/b]
  259. I will write an alias /hawkee, that takes 3 (optional) arguments:[code]/hawkee [METHOD] [URL] [DATA][/code]The method can be either GET or POST, the URL can be anything (/ for main page) the DATA should be a string of variables like foo=bar&test=bla. Relative of the method we specified, we will send that DATA string either using the POST method or the GET method.
  260. In the mean-time, the script will keep track of all the cookies. If it recieves a [b]Set-Cookie[/b] request, it will store the [b]name=value[/b] into the text file 'hawkee_cookie.txt'. If the cookie already exists it will overwrite it. [b]Everytime[/b] the user requests a page, the script will check whether it has any cookies, and send them if it does. This is basically the same way your browser is doing it.
  261.  
  262. Now before I give you the snippet, let's take a look at the log-in form from the main page:
  263. [code]<form action="/phpBB2/login.php" method="post">
  264.   <input type="hidden" name="login" value="1">
  265.   <input type="hidden" name="redirect" value="/">
  266.   <input type="text" size=8 maxlength=130 name="username" class="ss">
  267.   <input type="password" size=8 maxlength=130 name="password" class="ss">
  268.   <input class="text" type="checkbox" name="autologin" checked>
  269.   <input type="submit" name="Submit" value="login" class="liteoption">
  270. </form>[/code]
  271. In order to log in we will have to send the following data string (if you are confused why we have to send this, please read the Q&A I told you to read):
  272. [b]login=1&redirect=/&username=[i]USERNAME_HERE[/i]&password=[i]PASSWORD_HERE[/i]&autologin=on&Submit=login[/b]
  273. to the url, using POST method:
  274. [b]/phpBB2/login.php[/b]
  275. In the snippet discussed above, this would make the following command:
  276. [b]/hawkee POST /phpBB2/login.php login=1&redirect=/&username=QuickStep&password=***&autologin=on&Submit=login[/b]
  277.  
  278. After we have recieved the cookie's from sending that request, we will have to open the following page, and retrieve the e-mail address:
  279. http://hawkee.com/phpBB2/profile.php?mode=editprofile
  280. In the snippet discussed above, this would make the following command:
  281. [b]/hawkee GET /phpBB2/profile.php mode=editprofile[/b]
  282.  
  283. So now that the theory about the snippet is discussed, here it is (please read the comments):[code]alias hawkee {
  284.   ; Open a new window, where we will output the data
  285.   window @hawkee
  286.   linesep @hawkee
  287.  
  288.   ; Set first parameter, which defaults to GET
  289.   var %method = $iif($1,$1,GET)
  290.  
  291.   ; Set second parameter, which defautls to /
  292.   var %page = $iif($2,$2,/)
  293.  
  294.   ; Set socket name
  295.   var %sock = hawkee $+ $ticks
  296.  
  297.   ; Open socket and send data to it
  298.   sockopen %sock www.hawkee.com 80
  299.   sockmark %sock %method %page $3
  300. }
  301. on *:SOCKOPEN:hawkee*:{
  302.   ; Connection has been made
  303.   aline @hawkee Connection established...
  304.   aline @hawkee MODE: $getmark($sockname,1-)
  305.  
  306.   ; Define command
  307.   var %a = sockwrite -n $sockname
  308.  
  309.   ; Define data string to send
  310.   var %string = $urlencode_string($getmark($sockname,3))
  311.  
  312.   ; First send GET/POST, next send Host
  313.   %a $getmark($sockname,1-2) $+ $iif($getmark($sockname,1) == GET && %string,$+(?,%string)) HTTP/1.1
  314.   %a Host: www.hawkee.com
  315.  
  316.   ; If there are cookies, we will send them
  317.   ; Remember: to send all cookies we must seperate them with ';'
  318.   if ($exists(hawkee_cookie.txt)) {
  319.     aline @hawkee Found cookie in your mirc directory, sending it now...
  320.     var %n = 1, %cookie
  321.     while ($read(hawkee_cookie.txt,%n)) {
  322.       ; Seperate the cookies with ';'
  323.       %cookie = $+(%cookie,$v1,;)
  324.       inc %n
  325.     }
  326.     aline @hawkee Sending cookie: %cookie
  327.  
  328.     ; Sending the cookie
  329.     %a Cookie: %cookie
  330.   }
  331.  
  332.   ; If method is POST, we need to include 2 extra parameters
  333.   if ($getmark($sockname,1) == POST) {
  334.     %a Content-Length: $len(%string)
  335.     %a Content-Type: application/x-www-form-urlencoded
  336.   }
  337.  
  338.   ; Force connection to close
  339.   %a Connection: close
  340.  
  341.   ;Just-to-make-sure requests:
  342.   %a Accept: */*
  343.   %a Accept-Charset: *
  344.   %a Accept-Encoding: *
  345.   %a Accept-Language: *
  346.   %a User-Agent: Mozilla/5.0
  347.  
  348.   if ($getmark($sockname,1) == POST) {
  349.     ; If we are using method POST we must include the data at the end
  350.     %a $crlf %string
  351.   }
  352.   else {
  353.     ; else we we send normal closing data
  354.     %a $crlf
  355.   }
  356. }
  357.  
  358.  
  359.  
  360. on *:SOCKREAD:hawkee*:{
  361.   sockread %tmp
  362.   if ($regex(%tmp,/^Set-Cookie: (.+?)=(.+?);/i)) {
  363.     aline @hawkee Recieved Cookie: $regml(1)
  364.     ; We found a cookie, let's store it
  365.     if ($read(hawkee_cookie.txt, w, $regml(1) $+ =*)) {
  366.       aline @hawkee Cookie already exists, overwriting...
  367.       ; Cookie already exists, overwriting...
  368.       write -l $+ $readn hawkee_cookie.txt $+($regml(1),=,$regml(2))
  369.     }
  370.     ; else we will just add it to the end
  371.     else write hawkee_cookie.txt $+($regml(1),=,$regml(2))
  372.   }
  373.   if ((!%tmp) && ($getmark($sockname,1) == POST)) {
  374.     ; We recieved the headers from the server, now it is time to open the profile page and try to retrieve
  375.     ; Your e-mail address with the cookies we just recieved
  376.     aline @hawkee Recieved headers from server
  377.     sockclose $sockname
  378.  
  379.     aline @hawkee Now opening page to view your profile
  380.     hawkee GET /phpBB2/profile.php mode=editprofile
  381.   }
  382.  
  383.   ; Now what we really wanted to do is retrieve the users email address, we will do that here
  384.   ; with a basic regular expression
  385.   if ($regex(%tmp,/name="email" .+? value="(.+?)"/i)) {
  386.     aline @hawkee Script succesfully found your e-mail address: $regml(1)
  387.     aline @hawkee We logged into your account at http://hawkee.com while submitting data and using cookies
  388.     aline @hawkee This ends our example...
  389.     sockclose $sockname
  390.   }
  391. }
  392.  
  393.  
  394. alias getmark {
  395.   ; $getmark(socketname,N)
  396.   ; This alias returns the Nth word from the socketmark from socket socketname
  397.   return $gettok($sock($1).mark,$$2,32)
  398. }
  399.  
  400. alias urlencode_string {
  401.   ; Encodes a whole string of data in the format name1=data1&name2=data2
  402.   ; Example: $urlencode_string(name1=test&name2=test2)
  403.   ; Returns: name1=%74%65%73%74&name2=%74%65%73%74%32
  404.   var %a = 1, %string = $1, %output
  405.   while ($gettok(%string,%a,38)) {
  406.     tokenize 61 $v1
  407.     if (%a != 1) %output = %output $+ &
  408.     %output = $+(%output,$1,=,$urlencode($2))
  409.     inc %a
  410.   }
  411.   return %output
  412. }
  413.  
  414. alias urlencode {
  415.   var %a = $regsubex($$1,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2)))
  416.   return $replace(%a,$chr(32),$chr(43))
  417. }[/code]
  418. Now when performing the following command with this snippet:
  419. [b]/hawkee POST /phpBB2/login.php login=1&redirect=/&username=QuickStep&password=***&autologin=on&Submit=login[/b]
  420. The output is:[code]-
  421. Connection established...
  422. MODE: POST /phpBB2/login.php login=1&redirect=/&username=QuickStep&password=***&autologin=on&Submit=login
  423. Recieved Cookie: PHPSESSID
  424. Recieved Cookie: phpbb2mysql_data
  425. Recieved Cookie: phpbb2mysql_sid
  426. Recieved Cookie: phpbb2mysql_data
  427. Cookie already exists, overwriting...
  428. Recieved Cookie: phpbb2mysql_sid
  429. Cookie already exists, overwriting...
  430. Recieved headers from server
  431. Now opening page to view your profile
  432. -
  433. Connection established...
  434. MODE: GET /phpBB2/profile.php mode=editprofile
  435. Found cookie in your mirc directory, sending it now...
  436. Sending cookie: PHPSESSID=175a37af57c12a7d70c26671012b...
  437. Script succesfully found your e-mail address: maxismijnnaam@hotmail.com
  438. We logged into your account at http://hawkee.com while submitting data and using cookies
  439. This ends our example...[/code][i]Note: Some data has been modified to secure my account, and to make it better fit on the page[/i]
  440.  
  441. [b]Conclusion:[/b]
  442. Logging in to a site is just a matter of sending the correct data the correct way, and keeping track of every cookie you recieve along the way (overwriting if it already exists).[/quote]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement