Good article
http://www.phrack.com/issues.html?issue=65&id=7#article
Tuesday, September 28, 2010
Tuesday, September 21, 2010
Shell Script while loop
Shell script is space sensetive,
There are space between "[" and "$i"
you have to use double parentheses.
While loop:
There are space between "[" and "$i"
you have to use double parentheses.
While loop:
#!/bin/bash
i=1
while [ $i -le 100 ] # loop 100 times
do
./readCMOSflag
i=$(( $i + 1 ))
# or you could use (( i++ ))
done
Print current Time
How to print current time in shell script:
$date
For example, if you want to print current seconds since Epoch, and current nanoseconds. %s means print seconds, and %N means print nanoseconds
$date +%s%N
If you want to see the details, please see man page of date
How to print current time in C:
You could use time() function, please see man(3) page
time_t could print out by using %ld
e.g.
time_t result;
result = time(NULL); // or time(&result);
printf("%ld", result); // or printf("%s\n", ctime(&result))
If you want to print out the sec and nsec of current time.
e.g.
#include <time.h>
void printCurrentTimeNsec()
{
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec);
}
When you compile this program, you need to add -lrt because of clock_gettime() function.
$date
For example, if you want to print current seconds since Epoch, and current nanoseconds. %s means print seconds, and %N means print nanoseconds
$date +%s%N
If you want to see the details, please see man page of date
How to print current time in C:
You could use time() function, please see man(3) page
time_t could print out by using %ld
e.g.
time_t result;
result = time(NULL); // or time(&result);
printf("%ld", result); // or printf("%s\n", ctime(&result))
If you want to print out the sec and nsec of current time.
e.g.
#include <time.h>
void printCurrentTimeNsec()
{
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec);
}
When you compile this program, you need to add -lrt because of clock_gettime() function.
Wednesday, September 15, 2010
Onion routing and Tor
Good link to explain what Onion routing is, beside wiki
http://www.ccs.neu.edu/home/priyanka/Onion Routing.html
Good link to explain what the Tor is:
http://www.iusmentis.com/society/privacy/remailers/onionrouting/
http://www.ccs.neu.edu/home/priyanka/Onion Routing.html
Good link to explain what the Tor is:
http://www.iusmentis.com/society/privacy/remailers/onionrouting/
Tuesday, September 14, 2010
Small-endian V.S. Big-endian
Samll-endian machine: Intel x86
e.g.
program value 0a0b0c0d // set data= 0x0a0b0c0d in program
register value 0a0b0c0d // 0a is high bits(31-24), and 0d is low bits(7-0)
memory value 0d0c0b0a // data in memory
suppose you input 0x00 00 00 a1 from the terminal, you use scanf to read it into a integer in C, it's value is 161.
however, it stores in memory as following: a1 00 00 00
In x86 machine, the format of file on disk is same as the format on memory.
suppose in a binary file, there are 4 byte content in the file, the content is as following: a1000000, if you use fread() to read this 4 byte into an integer
fread(&i, 4, 1), the value of i is 161.
the register value is the same as our real life value.
another example will be:
10th bytes of the memory: 0x0000000a
if you store this memroy address in memory, it should be 0a 00 00 00
Big-endian machine: PowerPC
please see more information at wiki:
http://en.wikipedia.org/wiki/Endianness
some thoughts about little endian:
integer 15 stores at file or memory at X86 is (4 bytes ):
e.g. int a = 15; a stores in memory is:
00001111 00000000 00000000 00000000
File is same as memory, everything in file need to load into memory first.
However, number 15 written in file is different, becuase it is two digits (open a new file, and write 15 in that file, and save it).
supposed to use ASICI Code to translate these two digits.
e.g.
program value 0a0b0c0d // set data= 0x0a0b0c0d in program
register value 0a0b0c0d // 0a is high bits(31-24), and 0d is low bits(7-0)
memory value 0d0c0b0a // data in memory
suppose you input 0x00 00 00 a1 from the terminal, you use scanf to read it into a integer in C, it's value is 161.
however, it stores in memory as following: a1 00 00 00
In x86 machine, the format of file on disk is same as the format on memory.
suppose in a binary file, there are 4 byte content in the file, the content is as following: a1000000, if you use fread() to read this 4 byte into an integer
fread(&i, 4, 1), the value of i is 161.
the register value is the same as our real life value.
another example will be:
10th bytes of the memory: 0x0000000a
if you store this memroy address in memory, it should be 0a 00 00 00
Big-endian machine: PowerPC
please see more information at wiki:
http://en.wikipedia.org/wiki/Endianness
some thoughts about little endian:
integer 15 stores at file or memory at X86 is (4 bytes ):
e.g. int a = 15; a stores in memory is:
00001111 00000000 00000000 00000000
File is same as memory, everything in file need to load into memory first.
However, number 15 written in file is different, becuase it is two digits (open a new file, and write 15 in that file, and save it).
supposed to use ASICI Code to translate these two digits.
Monday, September 13, 2010
Linux command
/* find */
find the filename include "snort"$ find / -name '*snort*'
/* cd */
go to last directory
$ cd -
/* sudo */
sudo <last command>
$ sudo !!
/* command conbination */
for large data, which include a lot new lines, space, or repeated data
$ cat out | sort | uniq | less
/* Makefile */
this command will not show up on the terminal if you start with '@'
makefile
build:
@mkdir dir
run many times of test program
$ make; while true do "./test"; done
/* VIM*/
VI go to the end of line$
VI go the beginning of the line
0
go to a specific line when your file is very large
$ vim filename 99999
/* stderr*/
use "2>&1" to have stderr go to the same place that stdout is going to:./myprogram > my_output_and_errors 2>&1
/* typescript*/
/* rescync*/
rescync: this is for back purposehttp://www.comentum.com/rsync.html
example:
rsync -r WorkSpace username@sr1s5.mesa.gmu.edu:/home/username/usernameWorkSpace
if the ssh port is not 22. For example, you backup storage behind a NAT, you forward router 2225 traffic your port 22 on your machine. you could do:
rsync -r -e "ssh -p 2225" ./srcDir username@hostname:/dstDir
/* cmp */
we could use cmp to compare two binary file.
$ cmp -l binaryfile1 binaryfile2
-l print out:
<the number of bytes (decimal) where not same> <content in binaryfile1> <content in binaryfile2>
/* diff */
we could creat patch by using diff. e.g. create kenerl patch
diff -Naur linux-2.6.11.12 linux-2.6.11.12-hw > patch1
/* GHex */
usefull tool of hex editor
/* tail*/
tail -f ./*: it is very useful for log files.
/* grep*/
grep -iHRn *pattern*: ignore case, file name of matching file, recersive search, line number
/* ssh*/
$!sshthis will executed the lastest ssh command, if you cannot remember the IP address
you could also try:
$!cd
if you cannot remember the directory.
/* nohup*/
$nohup commandIt is used when you in ssh terminal session. When you are running a program on the remote host, you don't want the program terminate after you close the terminal. If you use nohup, and it will not terminate the program when you close the terminal.
/* du */
$du -sh direcotry/* df */
/* Ctr+Alt + F1/F2.../F9*/
Press this key, you will see the command. Or text mode.
/* cat id_rsa.pub | pbcopy */
This command will put the content of di_ras.pub to clickboard. When you do pasting, it will paste the content of id_rsa.pub
$bg // let the program run at background
$fg // run foreground
killall while1(processname)
pkill while1
This will create a file named test on current directory. In this file, there are 10 bytes 0x00
if: input file; of: output file; bs: block size; count: the number of blocks
dd is to copy data from input file to output file
http://en.wikipedia.org/wiki//dev/zero
/* fdisk -l */
Show all the disk information. like how many partition in current hard disk. and how many partitions in other disks.
/* bg fg */
Ctr + Z, stoped the program$bg // let the program run at background
$fg // run foreground
/* kill */
kill -9 processIDkillall while1(processname)
pkill while1
/* dd */
dd if=/dev/zero of=test count=2 bs=5This will create a file named test on current directory. In this file, there are 10 bytes 0x00
if: input file; of: output file; bs: block size; count: the number of blocks
dd is to copy data from input file to output file
http://en.wikipedia.org/wiki//dev/zero
/* who */
Check who is logged in the serverFriday, September 10, 2010
install Xen on centOS 5
Useful link for installation:
http://www.howtoforge.com/installing-xen-on-centos-5.2-i386
http://www.howtoforge.com/installing-xen-on-centos-5.2-i386
Subscribe to:
Posts (Atom)