The First SHA1 Collision

CWI Institute in Amsterdam and Google genrate two PDF documents with the same SHA-1 digest. Google security blog - Announcing the first SHA1 collision SHA-1 collistion and Git If a file A with X hash in local repository and with X hash in remote (SHA-1 collistion between local and remote), would overwrite the local version? Nope. If it has the same SHA1, it means that when we receive the object from the other end, we will not overwrite the object we already have. So you have two cases of collision: the inadvertent kind, … The attacker kind … … So in this case, the collision is entirely a non-issue: you’ll get a “bad” repository that is different from what the attacker intended, but since you’ll never actually use his colliding object, it’s literally no different from the attacker just not having found a collision at all, but just using the object you already had (ie it’s 100% equivalent to the “trivial” collision of the identical file generating the same SHA1). See above. The only dangerous kind of collision is the inadvertent kind, but that’s obviously also the very very unlikely kind. Torvalds @ Git- Re: Starting to think about sha-256? ...

March 3, 2017 · 4 min · oopsmonk

Bash Quick Reference

Advanced Bash-Scripting Guide sed awk Internal Variables #current parent pid $$ #last background process pid $! #last exit status $? #current instance pid, Bash 4.x above. $BASHPID Arithmetic Expansion a=12 b=$(($a + 10)) b=`expr $a + 1` b=$(expr $a + 1) let b=$a+3 #let b=$a + 3 #incorrect let "b = $a + 3" declare -i b=$a+$a Manipulating Strings String is a number if [[ $var =~ ^-?[0-9]+$ ]]; then echo "$var is a number" fi if [[ ! $var =~ ^-?[0-9]+$ ]]; then echo "$var is not a number" fi Find String between two words or characters var="Hello there are (123340) and (123)" #last string between '(' and ')'. substr=$( echo $var | sed 's/.*(\(.*\)).*/\1/' ) #String between '(' and ')'. substr=$( echo $var | awk -v FS="(\(|\))" '{print $2 " " $4}' ) #String between 'there' and 'and'. substr=$( echo $var | awk -v FS="(there|and)" '{print $2}' ) #String between 'there' and 'and'. substr=$( echo $var | sed 's/.*there\(.*\)and.*/\1/' ) #String between 'there' and 'and'. substr=$( echo $var | grep -o -P '(?<=there).*(?=and)' ) Loop read variables #read from file echo "123, abc, hello world!" > /tmp/test echo "12 43, ddd, !" >> /tmp/test while IFS=',' read var1 var2 var3 do echo "var1=$var1 var2=$var2 var3=$var3" done < "/tmp/test" #read from variable x="one, two, three" while IFS=',' read var1 var2 var3 do echo "var1=$var1 var2=$var2 var3=$var3" done <<< $x iterate IP address #iterate class C ip address for i in 192.168.100.{1..10} do echo "$i" done #iterate class B ip address for x in 192.168.{1..5} do for i in $x.{1..10} do echo "$i" done done infinite while loop while : do echo "infinite loops [ CTRL+C to stop]" sleep 5 done Array # Simple array arrayA=( Mon Tue Wed Thu Fri Sat Sun ) echo "${!arrayA[*]}" # 0 1 2 3 4 5 6 echo "${#arrayA[*]}" # 7 echo "${arrayA[*]}" # Mon Tue Wed Thu Fri Sat Sun echo "${!arrayA[@]}" # 0 1 2 3 4 5 6 echo "${#arrayA[@]}" # 7 echo "${arrayA[@]}" # Mon Tue Wed Thu Fri Sat Sun echo "${arrayA[2]}" # Wed echo "$arrayA" # Mon echo "${arrayA[20]}" # null arrayA=( one two ) echo "${arrayA[*]}" # one two arrayA+=( three "four" ) echo "${arrayA[*]}" # one two three four # Key/Value declare -A arrayB=( ["Mon"]="Monday" ["Tue"]="Tuesday" ["Wed"]="Wednesday" ["Thu"]="Thursday" ["Fri"]="Friday" ["Sat"]="Saturday" ["Sun"]="Sunday" ) echo "${!arrayB[*]}" # Thu Tue Wed Mon Fri Sat Sun echo "${#arrayB[*]}" # 7 echo "${arrayB[*]}" # Thursday Tuesday Wednesday Monday Friday Saturday Sunday echo "${!arrayB[@]}" # Thu Tue Wed Mon Fri Sat Sun echo "${#arrayB[@]}" # 7 echo "${arrayB[@]}" # Thursday Tuesday Wednesday Monday Friday Saturday Sunday echo "${arrayB[2]}" # null echo "$arrayB" # null echo "${arrayB["Tue"]}" # Tuesday declare -A arrayB=( ["one"]=1 ["two"]="2" ) echo "${!arrayB[*]}" # one two echo "${arrayB[*]}" # 1 2 arrayB+=( ["three"]="3" ["four"]=4 ) echo "${!arrayB[*]}" # four one two three echo "${arrayB[*]}" # 4 1 2 3 arrayB+=( ["four"]="aa" ["five"]="5a1c" ) echo "${!arrayB[*]}" # four one five two three echo "${arrayB[*]}" # 4aa 1 5a1c 2 3 I/O redirection Forking Processes pid_perfix="/tmp/proc-" function doSomething(){ local pid_file="$pid_perfix$BASHPID" echo "this is task $1 : $pid_file " > $pid_file sleep 5 } w_pid="" for task in {1..5} do doSomething $task & w_pid+="$! " sleep 1 done for p in $w_pid do wait $p done #clean up for p in $w_pid do #del pid file rm "$pid_perfix$p" done exit 0

December 4, 2014 · 3 min · oopsmonk

Building MOC

clone MOC svn repository to github Ref: Converting a Subversion repository to Git $ sudo apt-get install subversion git-svn $ mkdir moc-svn $ cd moc-svn $ svn co svn://daper.net/moc/trunk $ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt $ cd .. $ mkdir moc-git $ git svn clone svn://daper.net/moc/trunk --no-metadata -A ./moc-svn/authors-transform.txt ./moc-git $ cd moc-git $ git svn show-ignore > .gitignore $ git add -f .gitignore $ git commit -m "Convert svn:ignore to .gitignore." $ mkdir ../moc-bare $ git clone --bare ../moc-bare $ cd ../moc-bare/moc-git.git #Create empty repository on GitHub. $ git push --mirror https://github.com/oopsmonk/moc-git.git install develop package for MOC (Ubuntu) $ sudo apt-get install build-essential libdb-dev gettext Optional libraries: Sound driver: ALSA - libasound2-dev JACK - libjack-dev Decoder: FLAC - libflac-dev MP3 - libmad0-dev, libid3tag0-dev sndfile, vorbis - libsndfile1-dev Network: libcurl4-gnutls-dev RCC: librcc-dev Resample : libsamplerate0-dev MIME magic: libmagic-dev After release 2.5 MOC will require libpopt. $ sudo apt-get install libasound2-dev libjack-dev \ libflac-dev libmad0-dev libid3tag0-dev libsndfile1-dev $ sudo apt-get install libcurl4-gnutls-dev librcc-dev \ libsamplerate0-dev libmagic-dev libpopt ----------------------------------------------------------------------- MOC will be compiled with: Decoder plugins: flac mp3 sndfile vorbis Sound Drivers: OSS ALSA JACK DEBUG: yes RCC: yes Network streams: yes Resampling: yes MIME magic: yes ----------------------------------------------------------------------- install develop package for MOC (Raspberry Pi) $ sudo apt-get install build-essential autoconf automake libtool $ sudo apt-get install libncurses5-dev libdb-dev gettext $ sudo apt-get install libasound2-dev libjack-dev libflac-dev \ libmad0-dev libid3tag0-dev libsndfile1-dev $ sudo apt-get install libcurl4-gnutls-dev librcc-dev libsamplerate0-dev libmagic-dev Build libpopt $ wget http://rpm5.org/files/popt/popt-1.16.tar.gz $ tar xf popt-1.16.tar.gz $ cd popt-1.16 $ autoreconf $ ./configure --prefix=/usr/lib --enable-shared $ make $ sudo make install check out from repository $ svn co svn://daper.net/moc/trunk moc-svn Build step $ cd moc-svn $ autoreconf $ ./configure --enable-debug --perfix=/path/to/dev $ make && make install Debugging $cd /path/to/dev $ ./bin/mocp --debug

August 23, 2013 · 2 min · oopsmonk

Redirect and Save iptables on Ubuntu 12.04

Redirect port 8080 to 80 sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 Check iptables setting sudo iptables -t nat -L Save configure to iptables.rules sudo iptables-save > /etc/iptables.rules Save Solution #1 Configre /etc/network/interfaces iface eth0 inet dhcp pre-up iptables-restore < /etc/iptables.rules Save Solution #2 Configure /etc/network/if-pre-up.d/iptablesload #!/bin/sh iptables-restore < /etc/iptables.rules exit 0 Configure /etc/network/if-post-down.d/iptablessave #!/bin/sh iptables-save -c > /etc/iptables.rules if [ -f /etc/iptables.downrules ]; then iptables-restore < /etc/iptables.downrules fi exit 0 Change permissions ...

July 5, 2013 · 1 min · oopsmonk

Install JDK1.4.2(32bit) on Ubuntu 12.04 LTS(64bit)

Here is an error occurred if installed directly: install.sfx.XXX: not found Solution: install g++-mltilib and JDK $ sudo apt-get install g++-multilib $ chmod +x j2sdk-1_4_2_19-linux-i586.bin $ ./j2sdk-1_4_2_19-linux-i586.bin ..... Do you agree to the above license terms? [yes or no] yes Unpacking... Checksumming... 0 0 Extracting... UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu). creating: j2sdk1.4.2_19/ creating: j2sdk1.4.2_19/jre/ creating: j2sdk1.4.2_19/jre/bin/ inflating: j2sdk1.4.2_19/jre/bin/java inflating: j2sdk1.4.2_19/jre/bin/keytool inflating: j2sdk1.4.2_19/jre/bin/policytool .... Creating j2sdk1.4.2_19/lib/tools.jar Creating j2sdk1.4.2_19/jre/lib/rt.jar Creating j2sdk1.4.2_19/jre/lib/jsse.jar Creating j2sdk1.4.2_19/jre/lib/charsets.jar Creating j2sdk1.4.2_19/jre/lib/ext/localedata.jar Creating j2sdk1.4.2_19/jre/lib/plugin.jar Creating j2sdk1.4.2_19/jre/javaws/javaws.jar Done. $ sudo mkdir -p /usr/lib/jvm $ sudo mv j2sdk1.4.2_19 /usr/lib/jvm/java-1.4.2_19 Java environment configuration. $ wget http://webupd8.googlecode.com/files/update-java-0.5b $ chmod +x update-java-0.5b $ sudo ./update-java-0.5b Select java-1.4.2_19 Check java version $ java -version java version "1.4.2_19" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04) Java HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)

June 20, 2013 · 1 min · oopsmonk

Remove the same files in two folders

有時在整理照片或文件時, 需要比對2個資料匣, 把重覆的檔案拿掉. Dwonload Source Here function usage(){ echo "Find the same file in two folders and remove it." echo "usage : ./comp-rm.sh target-dir source-dir" echo "remove the same files in target-dir." } if [ $# -ne 2 ]; then usage exit 1 fi target_dir=$1 source_dir=$2 f_list1=$(find "$target_dir" -type f) f_list2=$(find "$source_dir" -type f) for i in $f_list1; do echo $f_list2 | grep $(basename $i) >/dev/null && hit_str+=$i";" done if [ -z $hit_str ]; then echo "list is empty.." exit 0 fi export IFS=";" count=0 for hit_file in $hit_str; do echo "$hit_file" let count++ done echo "Do you want to remove these files ($count)?" read -p "Press 'Ctrl+C' stop, 'Enter' key to continue..." for hit_file in $hit_str; do echo "removing... $hit_file" rm -f $hit_file done exit 0

June 19, 2013 · 1 min · oopsmonk

How to split boot.img and get kernel config

boot_cm9.img file from mk802_legacy-compatibility_v1.zip Device: Rikomagic MK802 Script files : Split_bootimg.pl , extract-ikconfig ( in {kernel_source}/script ) Split boot.img Copy boot_cm9.img, Split_bootimg.pl, extract-ikconfig into ‘split_boot’ $ mkdir split_boot $ cd split_boot $ ./split_bootimg.pl boot_cm9.img Page size: 2048 (0x00000800) Kernel size: 8094708 (0x007b83f4) Ramdisk size: 178940 (0x0002bafc) Second size: 0 (0x00000000) Board name: Command line: console=ttyS0,115200 rw init=/init loglevel=8 Writing boot_cm9.img-kernel ... complete. Writing boot_cm9.img-ramdisk.gz ... complete. Get kernel image (boot_cm9.img-kernel) and ramdisk (boot_cm9.img-ramdisk.gz) Extract kernel config $ dd if=boot_cm9.img-kernel of=dd_uImage bs=1024 skip=1 7903+1 records in 7903+1 records out 8093684 bytes (8.1 MB) copied, 0.0178518 s, 453 MB/s $./extract-ikconfig dd_uImage > kernel_config Extract ramdisk $ mkdir ramdisk $ cd ramdisk $ gzip -dc ../boot_cm9.img-ramdisk.gz | cpio -i 6677 blocks $ tree . . ├── data ├── default.prop ├── dev ├── init ├── init.goldfish.rc ├── initlogo.rle ├── init.rc ├── init.sun4i.rc ├── init.sun4i.usb.rc ├── proc ├── sbin │ ├── adbd │ └── ueventd -> ../init ├── sys ├── system ├── ueventd.goldfish.rc ├── ueventd.rc └── ueventd.sun4i.rc Reference: HOWTO: Unpack, Edit, and Re-Pack Boot Images ...

September 12, 2012 · 1 min · oopsmonk