mIRC Homepage

using sockets to send web form

Posted By: TomT

using sockets to send web form - 29/05/03 03:27 AM

I am need of causing mirc to send information to a website using sockets. The process I want to use is to duplicate the information a browser would send for a web form. I am hoping someone can either show me the exact format the information would need to be sent in.. or possibly help me find a way of capturing that information while actually using a browser to send the form.. any ideas would be appreciated.
Posted By: Online

Re: using sockets to send web form - 29/05/03 08:52 AM

It depends on which method you use, GET or POST. In both cases, you'll have to track down the form elements and build up a data string based of variables and their corresponding, optional values.

Using the GET method is simple:
var %data = [color:blue]var[/color]=[color:brown]value[/color]&[color:blue]another_var[/color]=[color:brown]value[/color]
sockwrite -n $sockname GET /path/file.cgi? $+ %data HTTP/1.1
sockwrite -n $sockname Host: <host>
sockwrite -n $sockname Connection: close
sockwrite -n $sockname

However the POST method is a little bit complicated. You'll have to specify two additional header lines, and the form data is moved to the end of the request, below the ending CRLF:
var %data = [color:blue]var[/color]=[color:brown]value[/color]&[color:blue]another_var[/color]=[color:brown]value[/color]
sockwrite -n $sockname POST /path/file.cgi HTTP/1.1
sockwrite -n $sockname Host: <host>
sockwrite -n $sockname Connection: close
sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
sockwrite -n $sockname Content-Length: $len(%data)
sockwrite -n $sockname
sockwrite -n $sockname %data

For example, let's take the Search page of our lovely board.

First, we track down the form elements.
<form method="[color:red]post[/color]"
  <input type="hidden" name="[color:blue]Cat[/color]" value="" />
  <select name="[color:blue]Forum[/color]" class="formboxes">
    <option value="[color:brown]All_Forums[/color]">All Forums</option>
    <option value="[color:brown]CatSearch-1[/color]">*News and Discussions -----</option>
    <option value="[color:brown]latestnews[/color]" >Latest News</option>
    <option value="[color:brown]generaldiscussion[/color]" >General Discussion</option>
    <option value="[color:brown]CatSearch-2[/color]">*Support -----</option>
    <option value="[color:brown]mirchelp[/color]" >mIRC Help</option>
    <option value="[color:brown]connectionissues[/color]" >Connection Issues</option>
    <option value="[color:brown]scriptsandpopups[/color]" >Scripts & Popups</option>
    <option value="[color:brown]CatSearch-3[/color]">*Development -----</option>
    <option value="[color:brown]featuresuggestions[/color]" >Feature Suggestions</option>
    <option value="[color:brown]developerforum[/color]" >Developer Forum</option>
    <option value="[color:brown]bugreports[/color]" selected="selected">Bug Reports</option>
  <input type="text" name ="[color:blue]Words[/color]" size="30" class="formboxes" />
  <select name="[color:blue]Match[/color]" class="formboxes">
    <option value=[color:brown]"Entire Phrase[/color]">Entire Phrase</option>
    <option value="[color:brown]And[/color]">And</option>
    <option value="[color:brown]Or[/color]">Or</option>
    <option value="[color:brown]Username[/color]">By Username</option>
  <select name = "[color:blue]Old[/color]" class="formboxes">
    <option value="[color:brown]1day[/color]">Newer than 1 day</option>
    <option value="[color:brown]2days[/color]">Newer than 2 days</option>
    <option selected="selected" value="[color:brown]1week[/color]">Newer than 1 week</option>
    <option value="[color:brown]2weeks[/color]">Newer than 2 weeks</option>
    <option value="[color:brown]3weeks[/color]">Newer than 3 weeks</option>
    <option value="[color:brown]1month[/color]">Newer than 1 month</option>
    <option value="[color:brown]3months[/color]">Newer than 3 months</option>
    <option value="[color:brown]6months[/color]">Newer than 6 months</option>
    <option value="[color:brown]1year[/color]">Newer than 1 year</option>
    <option value="[color:brown]allposts[/color]">All posts</option>
  <input type="text" name="[color:blue]Limit[/color]" value="[color:brown]25[/color]" size="3"
  class="formboxes" />
  <input type="submit" name="[color:blue]buttsubmit[/color]" value="[color:brown]Submit[/color]"
  class="buttons" />

Yes I do realize that this is a somewhat tiring work, thus where the form uses the GET request, you can first open it on your browser, and learn the variable names from what it displays in the address bar.

If the POST method is used, the browser won't tell what it sends, but you can however use a packet capturing program such as Ethereal to capture the outgoing HTTP request and learn from it.

For this example, I decided to search for the word "remote" over the "scripts and popups" board one week back. And here's how the script will look like:
alias form sockopen form forums.mirc.com 80
On *:sockopen:form:{
  var %data = [color:blue]Cat[/color]=&[color:blue]Forum[/color]=[color:brown]scriptsandpopups[/color]&[color:blue]Word[/color]s=[color:brown]remote[/color] $+ $&
              &[color:blue]Match[/color]=[color:brown]entire phrase[/color]&[color:blue]Old[/color]=[color:brown]1week[/color]&[color:blue]Limit[/color]=[color:brown]25[/color]&[color:blue]buttsubmit[/color]=[color:brown]submit[/color]
  sockwrite -n form POST /dosearch.php HTTP/1.1
  sockwrite -n form Host: forums.mirc.com 
  sockwrite -n form Connection: close
  sockwrite -n form Content-Type: application/x-www-form-urlencoded
  sockwrite -n form Content-Length: $len(%data)
  sockwrite -n form 
  sockwrite form %data
On *:sockread:form:{
  var %s
  sockread %s
  while $sockbr {
    echo -s -> %s
    sockread %s

Paste this into the remote and type /form to begin.

Note: variable names are case sensitive; make sure they are typed correctly.

I hope it helped. If you need help on sending HTTP requests, check this page. Most likely I won't be here until Saturday night, but you're welcome to ask furthermore and hopefully someone else will be able to answer.
Posted By: Adrenalin

Re: using sockets to send web form - 29/05/03 04:03 PM

For me easily is to sniff what browser send to the server .. I prefer Iris .. And put that in script ..
© 2021 mIRC Discussion Forums