LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2005, 08:08 PM   #1
SocialEngineer
Member
 
Registered: May 2003
Distribution: Slackware
Posts: 236

Rep: Reputation: 31
Favorite scripts and hacks?


Anybody here have any favorite scripts/hacks they'd like to share?

I picked up a good one from Hacking: The Art of Exploitation, for defending from port scans.

Code:
#!/bin/sh
HOST="192.168.0.189"
/usr/sbin/tcpdump -e -S -n -p -l "(tcp[13] == 2) and (dst host $HOST)" | /bin/awk '{
# Output numbers as unsigned
  CONVFMT="%u";

# Seed the randomizer
  srand();

# Parse the tcpdump input for packet information
  dst_mac = $2;
  src_mac = $3;
  split($6, dst, ".");
  split($8, src, ".");
  src_ip = src[1]"."src[2]"."src[3]"."src[4];
  dst_ip = dst[1]"."dst[2]"."dst[3]"."dst[4];
  src_port = substr(src[5], 1, length(src[5])-1);
  dst_port = dst[5];

# Increment the received seq number for the new ack number
  ack_num = substr($10,1,index($10,":")-1)+1;
# Generate a random seq number
  seq_num = rand() * 4294967296;

# Precalculate the sequence number for the next packet
  seq_num2 = seq_num + 1;

# Feed all this information to nemesis
  exec_string = "nemesis tcp -fS -fA -S "src_ip" -x "src_port" -H "src_mac" -D "dst_ip" -y "dst_port" -M "dst_mac" -s "seq_num" -a "ack_num;

# Display some helpful debugging info.. input vs. output
  print "[in]  "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10;
  print "[out] "exec_string;

# Inject the packet with nemesis
  system(exec_string);

# Do it again to craft the second packet, this time ACK/PSH with a banner
  exec_string = "nemesis tcp -v -fP -fA -S "src_ip" -x "src_port" -H "src_mac" -D "dst_ip" -y "dst_port" -M "dst_mac" -s "seq_num2" -a "ack_num" -P banner";

# Display some helpful debugging info..
  print "[out2] "exec_string;

# Inject the second packet with nemesis
  system(exec_string);
}'
 
Old 02-23-2005, 05:21 AM   #2
scott_R
Member
 
Registered: Jul 2003
Location: Brighton, Michigan, USA
Distribution: Lots of distros in the past, now Linux Mint
Posts: 748

Rep: Reputation: 31
I'd probably post this in programming, just because it's not general enough to attract much attention from most users.
 
Old 02-23-2005, 08:40 AM   #3
SocialEngineer
Member
 
Registered: May 2003
Distribution: Slackware
Posts: 236

Original Poster
Rep: Reputation: 31
Yeah, didn't realize that. I guess if a mod decides to move it, that's cool.
 
Old 02-23-2005, 09:07 AM   #4
tangle
Senior Member
 
Registered: Apr 2002
Location: Arbovale, WV
Distribution: Slackware
Posts: 1,761

Rep: Reputation: 78
I like this one.

Code:
The following is a script that I add to the beginning of /etc/profile.  While 
the script is a nice idea, it's very easy for someone to avoid .  I've never 
had any of my systems cracked since I've started using it, so I have no idea 
if this script will actually stop anyone.  It would most likely catch someone 
in the act, after they exploited a security hole, but before the system has 
been r00ted.  A r00ted system wouldn't even bother reading /etc/profile.


-- Begin script added to /etc/profile --
# Kick and ban users that are UID 0 but are NOT root!
if [ `id -u` = "0" -a `echo $USER` != "root" ]; then

  # Lock the user out 
  passwd -l $USER

  # Save some info
  date >> /root/SHIT
  netstat -apent >> /root/SHIT
  ps auxww >> /root/SHIT
  w >> /root/SHIT
  
  w | mail -s "$USER has gained ROOT access" root@localhost

# Let EVERYONE know
wall << EOF

***********************************************************

          $USER has gained ROOT access!!!

***********************************************************

EOF

  for i in `ls /dev/pts/`; do
    echo -e "\n$USER has gained ROOT access!!\n" >> /dev/pts/$i
  done

  # Log it 
  logger -is -f /var/log/messages "$USER has gained ROOT access!!"

  # Let the luzer know
  echo -e "\a\n\n You are _NOT_ root!!\\n\n\a"

  # Kill the user and his processes
  skill -9 -u $USER
  
  ifconfig eth0 down
  
  # This should be redundant
  logout 
  exit
fi

# Attempt to catch those that su
alias su="su -"
-- End script added to /etc/profile --
 
Old 02-23-2005, 10:15 AM   #5
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved to Programming. Note to all: if you see a post which you think should be moved, click the link which reads "Report this post to a moderator". No one gets a slap for genuinely reporting a post, even if we disagree.
 
  


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
wireless hacks error e1000 Linux - General 0 01-06-2004 06:41 PM
questions about apache hacks digsby0007 Linux - Networking 3 12-23-2003 02:13 PM
too many hacks running now !?! virgin Linux - Newbie 1 07-05-2003 08:38 PM
Audio hacks Freaksta Linux - General 1 06-26-2003 02:13 PM
Hollywood hacks P2P! bripage General 6 08-05-2002 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 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