Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

Expect Banner Grabbing with Telnet

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
jpetter
Asked:
jpetter
  • 2
1 Solution
 
simon3270Commented:
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
 
jpetterAuthor Commented:
simon3270,

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

jpetter
0
 
jpetterAuthor Commented:
Spot on with the solution, and quick to respond...many thanks to simon3270.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now