Using sed to Download ComboFix automatically

Posted by user901398 on Super User See other posts from Super User or by user901398
Published on 2012-09-18T20:41:52Z Indexed on 2012/09/18 21:41 UTC
Read the original article Hit count: 210

Filed under:
|
|

I'm trying to write a shell script to grab the dynamic URL which ComboFix is located at at BleepingComputer.com/download/combofix

However, for some reason I can't seem to get my regex to match the download link of the "click here" if the download doesn't work. I used a regex tester and it said I matched the link, but I can't seem to get it to work when I execute it, it turns up an empty result. Here's my entire script:

 #!/bin/bash
 # Download latest ComboFix from BleepingComputer
 wget -O Listing.html "http://www.bleepingcomputer.com/download/combofix/" -nv
 downloadpage=$(sed -ne 's@^.*<a href="\(http://www[.]bleepingcomputer[.]com/download/combofix/dl/[0-9]\+/\)" class="goodurl">.*$@\1@p' Listing.html)
 echo "DL Page: $downloadpage"
 secondpage="$downloadpage"
 wget -O Download.html $secondpage -nv
 file=$(sed -ne 's@^.*<a href="\(http://download[.]bleepingcomputer[.]com/dl/[0-9A-Fa-f]\+/[0-9A-Fa-f]\+/windows/security/anti[-]virus/c/combofix/ComboFix[.]exe\)">.*$@\1@p' Download.html)
 echo "File: $file"
 wget -O "ComboFix.exe" "$file" -nv
 rm Listing.html
 rm Download.html
 mkdir Tools
 mv "ComboFix.exe" "Tools/ComboFix.exe" -f

The first two downloads work successfully, and I end up with: http://www.bleepingcomputer.com/download/combofix/dl/12/

But it fails to match the final sed that will give me the download link.

The code it's supposed to match is:

<a href="http://download.bleepingcomputer.com/dl/6c497ccbaff8226ec84c97dcdfc3ce9a/5058d931/windows/security/anti-virus/c/combofix/ComboFix.exe">click here</a> 

© Super User or respective owner

Related posts about linux

Related posts about command-line