Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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!
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..
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.