LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-31-2005, 02:57 PM   #1
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Rep: Reputation: 15
bizarre piping behaviour


Forgive me if this question seems off-topic but I can't really find a forum that seems more apropos for it, and since the purpose is security related, I put it here.
When I grep for non-icmp output from tcpdump, the following works as intended.

tcpdump -n -vvv | grep 'arp' | perl ps2.pl

where 'perl ps2.pl' is the sub-command that runs a script of mine (ps2.pl) under the perl interpretor, using the grepped output of tcpdump. The script is trivial at this point, all it wants to do is take the input being piped to it using the ol' angle brackets thangy:

while(<>){
print "######" . $_;
`play question.wav`;
}

However, when I:

tcpdump -n -vvv | grep 'icmp' | perl ps2.pl

somehow, some way, the output (lines from tcpdump having 'icmp') don't get piped into the script, instead, these lines get printed on the screen, but don't go into the script --- what is happening? I tried some "2>&1" type stuff, to no avail. And like I said, the input gets piped successfully if the search term is 'arp' or other non-icmp terms, but as soon as the term being grepped for is icmp, boom, the output stops going where I want it to.
Help!
 
Old 07-31-2005, 06:25 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I gotta be honest that that's REALLY odd. I've never seen such behavior myself. What happens if you remove the '| perl ps2.pl' from the end of it?
 
Old 08-01-2005, 09:58 AM   #3
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Original Poster
Rep: Reputation: 15
Tell me about it! When I go:

tcpdump -n -vvv | grep 'icmp'

and then get GRC to scan me, it prints out output lines, like:

00:53:31.701798 IP (tos 0x0, ttl 119, id 32768, offset 0, flags [none], proto 1, length: 28) 4.79.142.206 > 26.6.8.14: icmp 8: echo request seq 0
00:53:32.187198 IP (tos 0x0, ttl 119, id 32768, offset 0, flags [none], proto 1, length: 28) 4.79.142.206 > 26.6.8.14: icmp 8: echo request seq 0
00:53:32.687328 IP (tos 0x0, ttl 119, id 32768, offset 0, flags [none], proto 1, length: 28) 4.79.142.206 > 26.6.8.14: icmp 8: echo request seq 0

but when I try to pipe these lines into my perl script, they don't get there, although as long as the grep-string isn't 'icmp', the outputted lines WILL get into the script! I know, this is really strange, and I don't have a clue what is happening..
 
Old 08-01-2005, 12:16 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Ok, give the following a try:
Code:
tcpdump -n -vvv | grep icmp 2>&1 | perl ps2.pl
Also, it might help to check that you have the latest version of the GNU coreutils.
 
Old 08-01-2005, 02:26 PM   #5
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Original Poster
Rep: Reputation: 15
No, that's what I thought, too --- at first: It's using 2 STDIN and STDERR or STDOUT, when it should be using just one of them (like I mentioned in the OP, "...tried 2>&1 stuff ...") but it doesn't help.
This is too wierd. When I use:
tcpdump -n -vvv | grep 'icmp' | perl ps2.pl
the output goes to the screen, not the script, but when I use:
tcpdump -n -vvv | grep 'arp' | perl ps2.pl
the output successfully gets directed into the script.
 
Old 08-01-2005, 02:29 PM   #6
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Original Poster
Rep: Reputation: 15
Oh yeah, I forgot to mention I'm running a fresh install of FC4, with "yum -y update" ran every day. Does this mean I have the latest core utilities?
 
Old 08-01-2005, 02:36 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yeah, you probably do. Just as an FYI, I am unable to reproduce this behavior on any of my boxes.

Edit: FYI, versions are as follows:
tcpdump version 3.8.3
libpcap version 0.8.3
grep (GNU grep) 2.5.1

Last edited by Matir; 08-01-2005 at 02:38 PM.
 
Old 08-01-2005, 04:29 PM   #8
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Original Poster
Rep: Reputation: 15
What I have:

tcpdump version 3.8
libpcap version 0.8.3
grep (GNU grep) 2.5.1

which is odd, given my frequent runs of "yum -y update" --- I would have thought that I'd have the latest versions of everything including tcpdump of which I have version 3.8 and not version 3.8.3 that you have.
 
Old 08-01-2005, 05:09 PM   #9
tom_from_van
Member
 
Registered: Jul 2005
Posts: 50

Original Poster
Rep: Reputation: 15
Oh well, thank god for the fact there's more than one way to do things --- how does that turbo-geek saying go? tim-toady or smt equally special.
I thought I would build as much functionality as I could by cobbling apps together on the command line just as an exercise in command line skills, of which i have a pitifull lack, having been such a recent microsoft defector (I've been running FC4 for a week now). But in the end, I put more functionality in the script instead of the command line with the following:

#!/usr/bin/perl
open ZZ, "tcpdump -n -vvv 2>&1 | " or die "I died because I couldn't start the input pipe $!\n";
print "I seem to have started ... \n";
while(<ZZ>){
if($_=~/icmp/){
print "#---> " . $_;
}
}
close ZZ;
exit 0;

And it works.
I've tried EVERYTHING involving line buffering specifications, wide/narrow character settings, snaplen, the works. Still, as soon as the grepped-for term is icmp and not ANYTHING else, output stops going into the script, so I gave up and decided to use regex's within the script instead of grepping on the command line. It's probably better this way anyway. But I'm still absolutely mystified as to why changing the grep-string to "icmp" has the effect that it does.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with piping mijohnst Linux - General 7 10-21-2005 04:14 PM
Bizarre Firefox behaviour BajaNick General 7 03-06-2005 03:56 PM
Bizarre Firebird behaviour m0rl0ck Linux - Software 2 10-29-2003 06:40 PM
Piping Processes (a little different) mackie_lin Programming 4 12-27-2002 08:17 AM
xmms BIZARRE behaviour? chaoticNight Linux - General 4 04-26-2002 06:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 05:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration