getting root acccess without sudo

Dec 29
2007
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "sys/types.h"
#include "unistd.h"
#include "stdlib.h"
#include "stdio.h"
 
int main(int argc, char** argv)
{
    int root_id = 0;
    char *command = argv[1];
 
    if(!command)
        command = "/bin/bash";
 
    setuid(root_id);
    system(command);
    exit(0);
}

root# gcc -o temproot temproot.c
root# chmod +s temproot
nobody$ alias root=’temproot “su – root”’
nobody$ root

bashrc

Dec 29
2007
export PATH=$PATH:$HOME/bin:/usr/sbin:/sbin:$HOME/network
export TERM=linux
export gemdoc=`gem environment gemdir`/doc
 
function prompt_set {
 
 local GRAY="\[\033[1;30m\]"
 local LIGHT_GRAY="\[\033[0;37m\]"
 local CYAN="\[\033[0;36m\]"
 local LIGHT_CYAN="\[\033[1;36m\]"
 local NO_COLOUR="\[\033[0m\]"
 
 case $TERM in
    xterm*|rxvt*)
        local TITLEBAR='\[\033]0;\u@\h:\w\007\]'
        ;;
    *)
        local TITLEBAR=""
        ;;
 esac
 
local temp=$(tty)
local GRAD1=${temp:5}
PS1="$GRAY-$CYAN-$LIGHT_CYAN(\
$CYAN\u$GRAY@$CYAN\h$LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\
$CYAN\$(date +%H:%M)$GRAY:$CYAN\w\
$LIGHT_CYAN)$CYAN-$GRAY-$LIGHT_GRAY "
PS2="$LIGHT_CYAN-$CYAN-$GRAY-$NO_COLOUR "
}
 
prompt_set
 
alias get_visits="ssh l 'tail /home/postgres/stats.txt'"
alias __='history | tail -2 | head -1'
alias r="temproot `id -u`'"
alias sql='mysql --password=pass'
alias ..='cd ..';
alias ...='cd ../..';
alias ,='cd -'
alias e=exit
alias e=exit
alias v=vim
alias l='ls -lc -h --color=yes'
alias c=clear
alias top='top -d1'
alias hc='history -c'
alias gre=grep
alias gr=gre
alias gpre=gr
alias grp=gpre
alias le=less
alias mroe=more
alias mreo=mroe
alias h=history
alias pe='perl -e'
alias pc='perl -c'
alias t=date
alias d=date
 
function FOR {
        local count=$1
        start=0
        shift
        while [ $start -lt $count ]
        do
        $*
        sleep 1
                clear
                let start=$start+1
        done
}

nmap cleaner in Perl

Dec 29
2007
$”=@ARGV;/^\D+/||print for`nmap$”`

Lists and Values

Nov 30
2007

Perl

($a, $b) = (1, 2);
@arr    = (1, 2);

Python

 a, b = 1, 2
arr = 1, 
arr = 1,2

Ruby

 a, b = 1, 2
arr  = 1, 2
arr  = 1,2, *[11,22] # the same as
arr  = [1,2, [11,22]].flatten

auto_link and highlight

Nov 01
2007
auto_link(text){|link| hightlight(link, phrase)}

Opera password recovery

Oct 29
2007

Unwand – fast and free program for Opera password recovery.

Everyday UNIX Commands

Aug 23
2007

find
Recursively find and print all files, having ‘txt’ extention:
find ./ -type f -name "*.txt"

The same but case insensititve:
find ./ -type f -iname "*.txt"

cat all found ‘txt’ files:
find ./ -type f -name "*.txt" -exec cat '{}' \;

rm all found ‘txt’ files, starting with capital letter:
find ./ -type f -name "[A-Z]*.txt" -exec rm '{}' \;

rm all except ‘txt’ files:
find ./ -type f ! -name "*.txt" -exec rm '{}' \;

grep
Find and print all lines in all files, containing ‘tester’:
grep tester *

Find and print all lines of all files, which do not contain ‘tester’:
grep -v tester *

The same but recursively:
grep -r -v tester *

The same but case insensitive:
grep -i -v tester *

The same but coloured:
grep -n -r --color=auto -v tester *

processes
simple Perl daemon:
perl -e 'use POSIX qw(setsid); fork; setsid; sleep 1, print $c++,$/ while 1'

checking the process existance: ps x | perl

another way to find the process id: pgrep perl

kill all processes, related to perl interpreter:pkill perl

monitor all processes within 1 second interval:top -d1

monitor all processes, which access the storage devices:iotop -d1

monitor all open files (pipes, sockets, directories, etc.):lsof

archive
Archive directory and all files and sub-directories:
tar cvf home.tar /home

The same but gzip compresses:
tar zcvf home.tar.gz /home

The same but bzip2 compressed:
tar jcvf home.tar.bz2 /home

“untar” gzip compressed archive:
tar zxvf home.tar.gz

“untar” bzip2 compressed archive:
tar jxvf home.tar.gz

column extraction, assuming, that all user names are needed “/etc/passwd”:

cut command
cat /etc/passwd | cut -f1 -d:

awk script
cat /etc/passwd | awk -F':' '{print $1}'

Perl source code
perl -ne '/(\w+)/ && print $1,$/' /etc/passwd

Ruby source code
ruby -ne 'puts $1 if /(\w+)/' /etc/passwd

ISO image manipulation

ISO image creation:
dd if=/dev/cdrom of=/tmp/cdr.iso
mkisofs -rJTV "books label" /home/books > /tmp/books.iso

ISO image reading:
mount -o loop -t iso9660 /tmp/books.iso /mnt/isoimage

Ruby one-liners (file manipulation)

Jul 20
2007
# number each line of a file
ruby -ne 'puts "#{$.}\t#{$_}"' file.txt
 
# print all non-blank lines
ruby -pe '$_.chomp.empty? and next' file.txt
 
# number and print all non-blank lines
ruby -ne '$_.chomp.empty? or print $.,"\t", $_' file.txt
 
# number and print each blank line
ruby -ne 'puts $. if $_.chomp.empty?' file.txt
 
# reverse order of lines (`tac` style)
ruby -e 'puts File.open($< .filename).readlines.reverse' file.txt
 
# print matched string from lines, matching the pattern
ruby -ne 'puts $_.scan(/^\w+/)' /etc/passwd
 
# triple space a file and reverse order of lines
ruby -e '$,="\n\n\n"; puts File.readlines($<.filename).reverse.join' file.txt
 
# print first line of a file (emulate 'head -1')
ruby -ne 'puts $_; break' file.txt
ruby -pe '$. == 1 or break' file.txt
 
# print last line of a file (emulates 'tail -1')
ruby -ne 'END{puts $_}' file.txt
 
# print last line number (emulates 'wc -l')
ruby -e 'loop{gets or break}; puts $.' file.txt
 
# print only lines that match a regular expression (emulates 'grep')
ruby -pe 'next if not /regex/' file.txt
 
# print only lines that do not match a regular expression (emulates 'grep -v')
ruby -pe 'next if /regex/' file.txt
 
# print section of file between two regular expressions, /^root/ and /^nobody/
ruby -ne 'puts $_ if /^root/../^nobody/' file.txt
 
# print file and remove duplicate, consecutive lines from a file (emulates 'uniq')
ruby -ne '$_.eql? $; or puts $_;$; = $_;' file.txt
 
# print file except for blank lines
ruby -pe 'next if $_.chomp.empty?' file.txt
ruby -pe 'next if /^\s*$/' file.txt
ruby -pe 'next if $_.split(/\S+/).size < 2' file.txt
 
# print file except for lines, starting with digit (unclear and inefficient)
ruby -pe 'next if (48..57).to_a.include?($_.split(//)[0][0])' file.txt
 
# delete all leading blank lines at top of file
ruby -pe '$,="$." if not $_.chomp.empty?; $, or next' file.txt
 
# print section of file from regex to end of file
ruby -pe '$,="$." if /regex/; $, or next' file.txt
 
# delete leading and trailing whitespace from each line
ruby -pe '$_.strip!.sub!(/$/, "\n")' file.txt
ruby -ne 'puts $_.strip! + $/' file.txt
 
# delete leading whitespace from the beginning of each line
ruby -ne 'puts $_.lstrip! || $_' file.txt
 
# convert DOS newlines (CR/LF) to Unix format (LF)
ruby -i -pe 'sub(/\r\n/, "\n")' file.txt

compare the ip address of different hostnames

Jul 20
2007
require "socket"
 
unless ARGV.size == 2
 raise ArgumentError,
   "Expected two hostnames, got #{ARGV.size}"
end
 
h1,h2 = ARGV
 
begin
  h1,h2 = Socket::getaddrinfo(h1, 7)[0][3], Socket::getaddrinfo(h2, 7)[0][3]
rescue
  print "#{$!}...\texiting\n"
  exit
end
 
if h1.eql? h2
  puts "hosts have the same ip address: #{h1}"
else
  puts "hosts differ: #{h1} #{h2}"
end

nmap output cleaner

Jul 19
2007
arg = ARGV.join(" ")
arg.empty? and exit
 
puts %x[nmap #{arg} 2>/dev/null].scan(/^\d+.+/)

Calendar

July 2010
M T W T F S S
« Apr    
 1234
567891011
12131415161718
19202122232425
262728293031  

Tags