Using Tools such as AWK, GREP, NAWK, XARGs on the Command Line

Extract the requests from an access_log that match the IPs from a list.

We have your common log formatted access_log. We wish to get all the requests that match the IPs from a list of IPs in a text file called ip_list.txt.

# awk '/.*/ {print "cat access_log | grep "$1" >> extract.txt "}' ip_list.txt | sh


Find out the Files That Contain Certain Text


It is common to want all the names of the files that contain a certain text. For instance, say inside a script directory you want to find all the scripts that contain a certain database name or a piece of text.

 find . -name '*.sh' | xargs grep -il '_KingKongDB'


Find out required libraries for C/C++ functions

Here we want to use the function sem_init, but we are not too sure of what libraries to link with. We can use 'nm' and 'grep' on the libraries (/usr/lib on linux).

# nm --print-file-name /usr/lib/* 2> /dev/null |grep sem_init

This command will return results with strings containing '/usr/lib/libpthread.a'. From this you know that you have to link with the option -pthread.


Replace a value in multiple files and write the output files to a new directory

In this example we have xml files such as Nokia-220s.xml, Nokia-2330.xml etc. We want to replace the value 'Spec-Handler' in these files with a new value called 'Nokia-WAP' and then write these files into a new directory called 'new'


# ls -l Nokia* |awk '{print "sed","'\''s/Spec-Handset/Nokia-WAP/g'\'' " $9 " >new/"$9}' |sh


Replace the newline ('\n') character at the end of a line with something else (a comma in this case)


cat addresses.txt | tr '\n' ','





find . -type f | grep -v '\.svn' | xargs perl -pi -e 's/\r\n/\n/g' 

cat access_log | grep 217.124.181.30 |sed -n 's/.*\("[a-zA-Z][^"]*"\)$/\1/pg'

Break Out of Web Proxy Frames

Aim
To break out of Web Proxy Frames or any frames for that matter all you have to do is add the javascript shown below to your web page and replace the codediaries.com/break.html link with your own link. Web Proxies can sometimes be a nuisance to webmasters as these proxies sometimes stop adds and mangle content. With this code snippet, you can easily break out of 98% of Web Proxies, provided they have javascript turned on. Let's bust all those web proxies!

 1. <script>
 2. if (top.location!=("http://codediaries.com/break.html")) {
 3.             top.location = "http://codediaries.com/break.html";
 4. }
 5. </script>
Hide line numbers

To see this in action visit the link http://codediaries.com/break.html using a web proxy.

Unfortunately Web Proxies are a little smarter than your average Frame and they tend to rewrite and insert a lot of javascript code. You get around this by obfuscating the javascript code using any online obfuscater. Once done, the code will look like this.

 1. <script>
 2. var _0x5135=["\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x68\x74\x74\x70\x3A\x2F\x2F\x63\x6F\x64\x65\x64\x69\x61\x72\x69\x65\x73\x2E\x63\x6F\x6D\x2F\x62\x72\x65\x61\x6B\x2E\x68\x74\x6D\x6C"];if(top[_0x5135[0]]!=(_0x5135[1])){top[_0x5135[0]]=_0x5135[1];} ;
 3. </script>
Hide line numbers

Javascript obfuscators are readily available and most of them are online. Just search for "javascript obfuscator" in your favourite search engine.

Once you learn this simple trick you can now make changes and experiment on breaking these Web Proxies and Frames. Use this as a starting point for your web proxy demolition.