?
Solved

Expect Banner Grabbing with Telnet

Posted on 2014-03-25
3
Medium Priority
?
617 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

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 …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

752 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