Solved

Expect Banner Grabbing with Telnet

Posted on 2014-03-25
3
592 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 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debug script powershell wmi 3 25
Adding a countdown to HTA 12 114
Merging text files strings with filename 18 56
Help with Progress 4gl Rounding Function 6 60
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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