Cannot kill hacker process with my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot kill hacker process with my script
# 1  
Old 08-02-2010
Cannot kill hacker process with my script

I want to kill a process of xterm that is run by hacker with my login name.
So, I write a shell script to do my goal.
I run 2 xterm and then I run my script on a first xterm. it should kill the process of a second xterm but it doesn't.Why?

Here is my code :
Code:
#!/bin/ksh
myps=$(ps -f|grep xterm|cut -d ' ' -f3)
mytty=$(tty|cut -c 6-10)
hackerps=$(ps -fu $(logname)|grep xterm| cut -d ' ' -f3)
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)
set -A mycurrent $myps
set -A hackercurrent $hackerps
set -A hackerttycurrent $hackertty
i=0

ttyother=0
while [ $i -le 400 ]
#!/bin/ksh
myps=$(ps -f|grep xterm|cut -d ' ' -f3)
mytty=$(tty|cut -c 6-10)
hackerps=$(ps -fu $(logname)|grep xterm| cut -d ' ' -f3)
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)
set -A mycurrent $myps
set -A hackercurrent $hackerps
set -A hackerttycurrent $hackertty
i=0

ttyother=0
while [ $i -le 400 ]
do
 if [ $i -eq 390 ]
 then
     j=0
     for j in ${#hackerttycurrent[*]}
     do
     if [ $hackerttycurrent[j] != $mytty ]
     then
        ttyother=$(( ttyother+1 ))
        kill -9 $hackercurrent[j]
        echo Kill $ttyother other terminal already
     else
     echo Now has $ttyother other terminal run by $(logname)
        echo None of other terminal was killed
     fi
     done
 fi
 echo $i

 i=$(( i+1))
done
banner Program Finish!

my process id is a string so it cannot kill by this command "kill -9 processid"?
# 2  
Old 08-02-2010
I am not sure what the problem is but when using an array element in bash, you might want to write:
Code:
     kill -9 ${hackercurrent[j]}
#instead of
     kill -9 $hackercurrent[j]

Quote:
my process id is a string so it cannot kill by this command "kill -9 processid"?
That should be no problem - maybe you had an additional j at the end of your pid.

Best post your error message here or use set -x and echo to see what your variables contain in the various steps of your script.
# 3  
Old 08-02-2010
Another thing that might trip you up is using cut. You are assuming that there are always two blanks between the user name and the process id. In the case where the PID is shorter than 5 digits then there will be more leading blanks, and the cut command will not pick up the right information. (I checked ps output from both a Linux and FreeBSD system and neither left justify the PID.) If I were writing the script, I'd do something like this:

Code:
ps -fu $USER | awk '{ print $2}'

which will generate a list of process IDs regardless of the number of blanks that separate the user name from the PID.
# 4  
Old 08-04-2010
It's work but it kill my process too in sometime but sometime it does as my goal. Why?
Code:
#!/bin/ksh
myps=$(ps -f|grep xterm|awk '{print $2}')
mytty=$(tty|cut -c 6-10)
hackerps=$(ps -fu $(logname)|grep xterm| awk '{print $2}')
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)
set -A mycurrent $myps
set -A hackercurrent $hackerps
set -A hackerttycurrent $hackertty
i=0

ttyother=0
while [ $i -le 400 ]
do
 if [ $i -eq 390 ]
 then
     j=0
     while [ $j -lt ${#hackerttycurrent[*]} ]
     do
     if [ ${hackerttycurrent[$j]} != $mytty ]
     then
        ttyother=$(( ttyother+1 ))
        kill ${hackercurrent[$j]}
        echo Kill $ttyother other terminal already
     else
     echo Now has $ttyother other terminal run by $(logname)
        echo None of other terminal was killed
     fi
     j=$(( j+1 ))
     done
 fi
 echo $i

 i=$(( i+1))
done
banner Program Finish!

# 5  
Old 08-04-2010
You're going to have the same problem with the other cut command:

Code:
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)

For the times that it fails, there are probably enough extra blanks in the line that picking up 'field 10' isn't getting the tty, but some other string. Then when you compare these to your tty name they will never match and you'll kill your session. Use the same technique with awk to pick up the correct tty field from the ps output.

If you want to be doubly sure that you don't kill your xterm, you could pass the process id to the script (it's possible to have the script dig this info out, but easier to pass it in). If your script is called kill_hacker, the command line might look something like:

Code:
kill_hacker $PPID

and the code in the script could be changed to test that the process id you're about to kill isn't the one passed in:

Code:
dont_kill=$1           # get xterm pid that we want not to kill
if [[ -z $dont_kill ]]
then
      echo "abort: missing process-id on command line"
      exit 1
fi
:
:
while (( $j < ${#hackerttycurrent[*]} ))
do   
        if [[ ${hackercurrent[$j]} != $dont_kill ]]
        then
                kill -9 ${hackercurrent[$j]}
                echo " killed: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        else
                echo "skipped: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        fi

        j=$(( j+1 ))
done

With this you could also elminate the need to get the tty information from the ps output.
# 6  
Old 08-05-2010
Quote:
Originally Posted by agama
You're going to have the same problem with the other cut command:

Code:
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)

For the times that it fails, there are probably enough extra blanks in the line that picking up 'field 10' isn't getting the tty, but some other string. Then when you compare these to your tty name they will never match and you'll kill your session. Use the same technique with awk to pick up the correct tty field from the ps output.

If you want to be doubly sure that you don't kill your xterm, you could pass the process id to the script (it's possible to have the script dig this info out, but easier to pass it in). If your script is called kill_hacker, the command line might look something like:

Code:
kill_hacker $PPID

and the code in the script could be changed to test that the process id you're about to kill isn't the one passed in:

Code:
dont_kill=$1           # get xterm pid that we want not to kill
if [[ -z $dont_kill ]]
then
      echo "abort: missing process-id on command line"
      exit 1
fi
:
:
while (( $j < ${#hackerttycurrent[*]} ))
do   
        if [[ ${hackercurrent[$j]} != $dont_kill ]]
        then
                kill -9 ${hackercurrent[$j]}
                echo " killed: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        else
                echo "skipped: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        fi

        j=$(( j+1 ))
done

With this you could also elminate the need to get the tty information from the ps output.
Thank you so much!!!
# 7  
Old 08-05-2010
Hi thsecmaniac ...

can you give me the full script ... i little bit confused if i see the full script i could understand better . Because i am in need to similiar thing.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kill all child process of a script

Hi guys i have a problem with a script... this script creates differents GUI with YAD... well i want that when i press the "Cancel" button on this graphical interface all the child process and even the same script should be killed #!/bin/bash function gui_start { local choice="" ... (4 Replies)
Discussion started by: maaaaarco
4 Replies

2. Shell Programming and Scripting

kill my processes which are run by hacker

how can I kill my processes which are run by hacker or another person who log in with my username and password (1 Reply)
Discussion started by: thsecmaniac
1 Replies

3. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

4. Shell Programming and Scripting

Script to Kill a Process by Name...

Hello all... new to these forums and a bit of a newbie with linux aswell. I need to figure out how to write a shell script to kill a process by name as given to the script as an argument. I've got that part working OK, but i need to make sure that the script does not allow processes that are... (6 Replies)
Discussion started by: cannon1707
6 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. Shell Programming and Scripting

Script to kill process...

hello Bros, I need to write some script that i can put it on crontab which checks for a process X if running. If the process X is ruuning then take the PID and kill it or display message that says process X is not running. I am using AIX 5.3 Thanks guys.:b: (2 Replies)
Discussion started by: malcomex999
2 Replies

7. Shell Programming and Scripting

Script to kill process

Hello guys, I have a process named monitoreo, with 'monitoreo start' my process start until i kill them, now i want to do 'monitoreo stop' to kill them. After 'monitoreo start' i have this process running: ps -af UID PID PPID C STIME TTY TIME CMD ati 10958 1495 ... (5 Replies)
Discussion started by: Lestat
5 Replies
Login or Register to Ask a Question