I need to extract the IP address and file path from a Nessus report using text handlers such as Grep / Awk / Sed / Tr etc....
I've got the script to isolate the IP address and file path but I need to handle the text further and remove the "has not been patched remote version...."
192.168.1.1 - C:\WINDOWS\SYSTEM32\GPPREF.DLL HAS NOT BEEN PATCHED. REMOTE VERSION : 6.2.9200.16384 SHOULD BE : 6.2.9200.16859"
192.168.1.2 THE REMOTE HOST IS MISSING ONE OF THE FOLLOWING ROLLUP KBS : - 4022719 - 4022722C:\WINDOWS\SYSTEM32\BCRYPT.DLL HAS NOT BEEN PATCHED. REMOTE VERSION : 6.1.7601.23796 SHOULD BE : 6.1.7601.23816"
192.168.1.3 - C:\WINDOWS\SYSTEM32\GPPREF.DLL HAS NOT BEEN PATCHED. REMOTE VERSION : 6.2.9200.16384 SHOULD BE : 6.2.9200.16859"
192.168.1.4 - C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL12.ACT7\MSSQL\BINN\SQLSERVR.EXE HAS NOT BEEN PATCHED. REMOTE VERSION : 2014.120.5000.0 SHOULD BE : 2014.120.5203.0"
So the end result should output the following from the above examples:
192.168.1.1 \WINDOWS\SYSTEM32\GPPREF.DLL
192.168.1.2 \WINDOWS\SYSTEM32\BCRYPT.DLL
192.168.1.3 \WINDOWS\SYSTEM32\GPPREF.DLL
192.168.1.4 \PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL12.ACT7\MSSQL\BINN\SQLSERVR.EXE
My script so far:
!/bin/bash
*if [ "$1" == "" ]; then
echo "No file specified."
echo "Usage: nesparse [filename.csv]"
else
cat $1 | tr -d "\n" | tr "\r" "\n" | awk -F '","' '{ print $5,$13 }' | grep "has not been patched." | sort -u | awk '{ match($0,/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*[cC]:\\(.*) has.*/; ip=substr $0,RSTART,RLENGTH);print ipadd ip} '
*
The section of the code below handles the text to the examples above, with $5 printing the IP address and $13 printing the file path:
!/bin/bash
* if [ "$1" == "" ]; then
echo "No file specified."
echo "Usage: nesparse [filename.csv]"
else
cat $1 | tr -d "\n" | tr "\r" "\n" | awk -F '","' '{ print $5,$13 }' |
grep "has not been patched." | sort -u *
The second awk pipe
* awk '{ match($0,/([0-9]+.[0-9]+.[0-9]+.[0-9]+).[cC]:\(.) has.*/ *
has the correct regex to match the output I need(see pic), but i'm having an issue with printing the regex'd output
Which is this line:
* ip=substr $0,RSTART,RLENGTH);print ipadd ip} ' *
Bonus point:
The IP regex matches any digit so 192.168.1.1 / 1.1.1.1 but its also matching against the version numbers in the above examples (2014.120.5203.0) ideally I need to modify this regex: * [0-9]+.[0-9]+.[0-9]+.[0-9]+ *
to restrict it to 0.0.0.0 --> 255.255.255.255