Tuesday, December 15, 2009

Find common data from three files

Given 3 files, each with names of thousands of customers who bought something from Amazon.com on that particular day. Find the common customers (i.e. common names in file1 and file2 and file3)

Solution:

1) assuming UNIX like systems:

cat f1 f2 | sort | uniq -d > tmpfile;

cat f3 tmpfile | sort | uniq -d

-------------------
Better options:
sort f1 f2 f3 |uniq -d

http://www.softpanorama.org/Tools/Sort/unix_sort_examples_collection.shtml
sort -t ':' -k 3,4 /etc/passwd

http://amazoninterview.blogspot.com/2007/05/find-common-data-from-three-files.html

find files with phone number

with following two formats
(xxx) xxx-xxxx and xxx-xxx-xxxx.

-l list only filename
grep -l -R --perl-regexp "\b(\(\d{3}\)\s*|\d{3}-)\d{3}-\d{4}\b" * > output.txt

(xxx) or xxx-
\(\d{3}\)\s*|\d{3}-
xxx-xxxx
\d{3}-\d{4}


http://www.wellho.net/regex/grep.html
http://www.robelle.com/smugbook/regexpr.html
(grep doesn't support "+" "|" "()"
(xxx) or xxx-
egrep "\([0-9]\{3\})|[0-9]\{3\}-" ./*
ls -1 list 1 file one line:
ls -1 | egrep 'DIV_(pharm|dental|vision)

perl replace "search" with "replace" and make the file as backup
perl -pi.bak -e's/searchs/replaces/' file1 file2 file3 fileN

Monday, December 7, 2009

Using aircrack-ng to hack WPA wireless protocol

Forum
http://forum.aircrack-ng.org/index.php?PHPSESSID=175264d2aaf388739350642fae99a34a&board=1.0

Windows network commands
http://whirlpool.net.au/wiki/?tag=Windows_NW_Diag_Cmds



linux manual
http://www.aircrack-ng.org/doku.php?id=getting_started
http://www.aircrack-ng.org/doku.php?id=airserv-ng



airserv-ng -d "commview.dll| {my adapter id}"
此时airserv-ng就在正常载入驱动后,同时开始监听本地的666端口。换句话说,airserv-ng提供的是该无线网卡的网络服务,其他计算机上的用户也可以连接到这个端口来使用这块网卡,如图5-30所示。


步骤2:现在可以使用airodump-ng来搜索当前无线环境了。注意,要另开启一个CMD,再输入如下命令:

airodump-ng 127.0.0.1:666
这里在IP地址处输入为本机即127.0.0.1,端口采用的是默认的666。

airodump-ng --channel number -w filename 127.0.0.1:666
这里输入“airodump-ng --channel 7 -w onewpa 127.0.0.1:666”,回车后可看到如图5-32所示的内容。


步骤3:现在,就可以和前面在BackTrack 2中讲述的一样进行Deauth攻击了,另开启一个CMD,输入(如图5-33所示):

aireplay-ng -0 1 -a AP’s MAC 127.0.0.1:666

在个别情况下,可能会在上面命令结束时出现wi_write<>:Operation now progress这样的提示,这个提示在很多无线网卡下都会出现,意思是当前进程调用被占用时,Deauth攻击在大多数情况下并不会受此影响。


步骤4:再开启一个CMD,输入命令查看是否捕获到WPA握手数据包。命令如下:

aircrack-ng 捕获的数据包名
如果没有捕获到WPA握手数据包,就会有显示的“0 handshake”,这个时候切回到刚才aireplay-ng所在的CMD中
重复进行Deauth攻击。

攻击过程中注意观察airodump-ng工作界面,当右上角出现如图5-35所示的提示时,就表示成功截获到WPA握手数据包了。


此时再次使用aircrack-ng 打开捕获的数据包,就可以看到截获到WPA <1 handshake>的显示了,
接下来便可以进行WPA本地破解了。


破解WPA-PSK输入命令如下:

aircrack-ng -w password.txt onewpa*.cap
这里介绍一个小技巧,可以在输入数据包名后面加一个*号,来自动将捕获的该名称的所有数据包整合导入。回车后,显示如图5-37所示。


如同在Linux下破解WPA一般耐心地等待,就可以看到WPA密钥成功解出了.