1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

communicate directly with a web server

Discussion in 'Security' started by mehdiali, Nov 13, 2007.

  1. #1
    hi every one
    How can send data to a page (communicate directly with a web server)whithout using any browsers(opera,firefox,...).
    I just heared something about telnet and i don't know anymore about it.
    Example:
    *
    *
    
    $ telnet example.org 80
        Trying 192.0.34.166...
        Connected to example.org (192.0.34.166).
        Escape character is '^]'.
        GET / HTTP/1.1
        Host: example.org
    
        HTTP/1.1 200 OK
        Date: Sat, 21 May 2005 12:34:56 GMT
        Server: Apache/1.3.31 (Unix)
        Accept-Ranges: bytes
        Content-Length: 410
        Connection: close
        Content-Type: text/html
        <html>
        <head>
        <title>Example Web Page</title>
        </head>
        <body>
    <p>You have reached this web page by typing &quot;example.com&quot;,
        &quot;example.net&quot;, or &quot;example.org&quot; into your web browser.</p>
        <p>These domain names are reserved for use in documentation and are not
        available for registration. See
        <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC 2606</a>, Section
        3.</p>
        </body>
        </html>
        Connection closed by foreign host.
        $
    
    HTML:
    *
    *
    This request can be made with the following PHP code:
    *
    *
    
    <?php
    
        $http_response = '';
    
        $fp = fsockopen('example.org', 80);
        fputs($fp, "GET / HTTP/1.1\r\n");
        fputs($fp, "Host: example.org\r\n\r\n");
    
        while (!feof($fp))
        {
          $http_response .= fgets($fp, 128);
        }
    
        fclose($fp);
    
        echo nl2br(htmlentities($http_response, ENT_QUOTES, 'UTF-8'));
    
     ?>
    
    PHP:
    *
    *
    I really wondered if someone explain examples to me.
    thank you in advance
     
    mehdiali, Nov 13, 2007 IP
  2. easyforexsignals.com

    easyforexsignals.com Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should be using webservices, this is what they are designed for.
     
    easyforexsignals.com, Nov 13, 2007 IP
  3. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #3
    mehdiali

    what you ask is typically what hackers do or try to do or want to learn to do ...

    hence

    i suggest we LEAVE the answer OPEN and unanswered by experts!
    NO honest person ever would want to do so and we definitely want to avoid to become hackers' helpers / info source here in DP forum !!!

    the examples you show are typical hacker abuse of sites
     
    hans, Nov 16, 2007 IP
  4. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hans
    1.i am not a hacker
    2.yes, it is clear that this script is used by somebody that most of them maybe are
    hacker.
    but you tell me, if i want to pervent them , i don't need to know how they do
    or what approach they use?
    3.this
    $ telnet example.org 80
    Trying 192.0.34.166...
    Connected to example.org (192.0.34.166).
    .....
    .......
    is a page of "OReilly.Essential.PHP.Security.Oct.2005" book.you can get it from flazx.om
    4. i understand you and you tell truth(it is a REALLY bad idea to give to such typical hacker questions any advice) but i'm not a hakcer.
    5.have a good day.
     
    mehdiali, Nov 16, 2007 IP
  5. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There are actually plenty of legitimate reasons to use something other than a browser to connect to a webserver and I have even used telnet in the past.

    Mostly I use "curl" or, if that doesn't suit my needs "wget". Just type "curl www.domain.com" on the command line and it will retrieve the webpage at that address. If you want to see the HTTP headers, try "curl --include www.domain.com"

    As for telnet, you actually have everything you need in your first post.
    [B]telnet example.org 80[/B]
        Trying 192.0.34.166...
        Connected to example.org (192.0.34.166).
        Escape character is '^]'.
        [B]GET / HTTP/1.1
        Host: example.org[/B]
    
        HTTP/1.1 200 OK
        Date: Sat, 21 May 2005 12:34:56 GMT
        Server: Apache/1.3.31 (Unix)
        Accept-Ranges: bytes
        Content-Length: 410
        ...
        ...
    Code (markup):
    The bits in bold are the bits you have to type. You will have to hit return twice after the "host: example.org" part but I couldn't figure out how to make a newline look bold :)

    You can request different pages on the website by using GET /otherpage.html HTTP/1.1. The same goes for curl: curl www.domain.com/otherpage.html

    It really depends on what you're trying to achieve. If you want this to happen in a script rather than by you typing on the command line then the PHP method looks like the right one to use. You can script in other languages but unless you're trying to learn a new language it's best to stick to what you know.

    One of the most common reasons I use curl with my own webservers is to time how long it takes to return just the html of the page. If I time it with a browser I end up having to wait for all of the javascript and css to download before I can even view the page. With the command line, I just type "time curl mydomain.com 2> /dev/null" and it prints out how long it took to retrieve the page.
     
    Ladadadada, Nov 29, 2007 IP