Solved

Expect Banner Grabbing with Telnet

Posted on 2014-03-25
3
562 Views
Last Modified: 2014-03-26
Hi,

I'm new to expect, but thought it would work well for scripting some banner grabbing. I've been working through the "Exploring Expect" book, and doing quite a bit of reading on the net, but can't seem to put it all together.

For this test script, I'm just trying to grab a banner from a service listening on a given port. Here is what I've got so far, and here is where I'm stuck. I suspect it's because I'm not using the correct string/syntax for one of my expect statement.

Here is what I manually type into the terminal
$ telnet 192.168.1.104 8834
Trying 192.168.1.104...
Connected to delta4.mynet.com (192.168.1.104).
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 400 Bad Request
Date: Tue, 25 Mar 2014 08:55:42 GMT
Server: NessusWWW
Connection: close
Expires: Tue, 25 Mar 2014 08:55:42 GMT
Content-Length: 208
Content-Type: text/html
X-Frame-Options: DENY
Cache-Control:
Expires: 0
Pragma :

Here is my script as it is now
--------------------------------------------------------------------------
#!/usr/bin/expect

if {[llength $argv] != 2} {
    puts "usage: $argv0 IP_address port\n"
    exit 1
}

set timeout -1
match_max 100000

set address [lindex $argv 0]
set port [lindex $argv 1]

spawn telnet $address $port
expect "^Escape*"
send "GET / HTTP/1.1\r\r"
expect "HTTP*"
expect eof

--------------------------------------------------------------------------
When I run the script, here is as far a it goes
$ ./get.exp 192.168.1.104 8834
spawn telnet 192.168.1.104 8834
Trying 192.168.1.104...
Connected to delta4.mynet.com (192.168.1.104).
Escape character is '^]'.
--------------------------------------------------------------------------

I realize I am not putting any expect statements in for the lines
Trying 192.168.1.104...
Connected to delta4.mynet.com (192.168.1.104).
but then, in the book, where the author has an example ftp snippet, he skips over all the lines following where he sends his password, and doesn't use an expect statement until he expects the ftp> prompt. So, following his lead, I thought it would be ok to skip over the first few lines received following the telnet statement until I got to the line
Escape character is '^]'.  Here is where the program hangs.

if anyone can help me out with this, I would appreciate very much.

Thanks,
jpetter
0
Comment
Question by:jpetter
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39954730
You don't need the "^" or "*" characters in your expect strings - have, for example

    expect "Escape"

You also don't strictly need the expect "HTTP" bit, since you are immediately following it with an expect eof - you can just have the expect eof.
0
 

Author Comment

by:jpetter
ID: 39955844
simon3270,

Thanks so much! That did the trick...I appreciate the quick help.

jpetter
0
 

Author Closing Comment

by:jpetter
ID: 39955847
Spot on with the solution, and quick to respond...many thanks to simon3270.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now