This forum is in archive mode. You will not be able to post new content.

Author Topic: [Perl]Grab Page With Socket  (Read 718 times)

0 Members and 1 Guest are viewing this topic.

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
[Perl]Grab Page With Socket
« on: February 05, 2014, 03:57:21 AM »
Any particular reason why this doesn't return anything? It also prints no errors either.

Code: (perl) [Select]
#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket;

my $socket = IO::Socket::INET->new(
   PeerAddr => 'www.google.com',
   PeerPort => 'http(80)',
   Proto    => 'tcp',
) or die 'Unable to get site';

print $socket "GET / HTTP/1.1";

Don't really have anything else for you, sorry.
« Last Edit: May 26, 2014, 05:02:11 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Perl]Grab Page With Socket
« Reply #1 on: February 05, 2014, 05:54:50 AM »
You're not sending a proper HTTP GET request.

As per RFC 2616, section 5 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html):

Quote
5 Request

A request message from a client to a server includes, within the first line of that message, the method to be applied to the resource, the identifier of the resource, and the protocol version in use.

        Request    = Request-Line              ; Section 5.1
                        *(( general-header        ; Section 4.5
                         | request-header         ; Section 5.3
                         | entity-header ) CRLF)  ; Section 7.1
                        CRLF
                        [ message-body ]          ; Section 4.3

5.1 Request-Line

The Request-Line begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF. The elements are separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.

        Request-Line   = Method SP Request-URI SP HTTP-Version CRLF

Therefore the working code would be:

Code: (Perl) [Select]
#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket;

my $socket = IO::Socket::INET->new(
   PeerAddr => 'www.google.com',
   PeerPort => 'http(80)',
   Proto    => 'tcp',
) or die 'Unable to get site';

print $socket "GET / HTTP/1.1\r\n";
print $socket "\r\n";
print my $rx_line =  <$socket>;

The final line prints only the first line from the server response (the HTTP 200 OK status).
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Perl]Grab Page With Socket
« Reply #2 on: February 05, 2014, 06:06:24 AM »
From a drunken stupor with memes on my mind, I been wanting to do this for a while now:



Lol, I don't have anything else to give this thread. So you went with Perl eh Lucid?
>>>import this
-----------------------------

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: [Perl]Grab Page With Socket
« Reply #3 on: February 05, 2014, 06:43:56 AM »
I knew I was missing something. I know there's tons of this code on the web, but I wanted to do it without looking at anyone else's code otherwise it'd be too hard not to copy and not learn anything.

I see I was misunderstanding what this was supposed to do however. I was attempting to grab the home page, like what this code does:

Code: (perl) [Select]
#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;

my $page = get('http://evilzone.org') or die 'Unable to get site';
print $page;
I see I need to read more about using sockets with perl. Thanks for your input vezzy.
« Last Edit: February 05, 2014, 06:56:13 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Perl]Grab Page With Socket
« Reply #4 on: February 05, 2014, 06:53:24 AM »
If your intention is web scraping, then yeah, raw sockets are too minimalistic.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: [Perl]Grab Page With Socket
« Reply #5 on: February 05, 2014, 06:56:32 AM »
Indeed they would be it seems. Not impossible though I imagine. Still it's obviously unecessary. Thanks vezzy.
« Last Edit: February 05, 2014, 06:57:11 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.