Category: Bash

  • Finding Malware URLs in W97M infected Word Docs

    Finding Malware URLs in W97M infected Word Docs

    An email with a trojan Microsoft Word document made it past the spam filter today at work. At least one user reported opening the attachment. The attachment was named: DOCO943488.doc, but running the file through virustotal.com it was clear that it’s been known by other names.. To help affected people find this page here are…

  • Bash Snippet: Luhn Algorithm

    Bash Snippet: Luhn Algorithm

    I like Bash, but it isn’t well suited for some tasks. For fun I sometimes ignore that. Occasionally people seem to find this useful. In that spirit, here is my implementation of the popular Luhn / mod10 algorithm used in credit card, IMEI, and other number sequences. download [luhn.zip] # Returns Luhn checksum for supplied…

  • Bash Snippet: Decimal to Binary Conversion

    Bash Snippet: Decimal to Binary Conversion

    Convert a decimal value into the binary representation and vice versa in Bash using only built-ins. If you know a better way, please let me know. To ensure a properly formatted expression for the arithmetic expansion in bin2dec, the dec2bin function prefixes zeros as needed to pad to a character count evenly divisible by 8.…

  • Detect Wi-Fi Clients on your DD-WRT Router

    Here is a script I wrote that scrapes the web interface of a router running DD-WRT. The script looks for the MAC addresses of wireless users. When it sees a MAC address that it hasn’t logged before it issues an alert. To help identify the new equipment, a portion of the MAC address is sent…

  • Bash Snippet: Trim Function

    Bash Snippet: Trim Function

    Occasionally I find myself wanting to removing leading and/or trailing occurrences of a character or string from a larger string in bash. A couple common uses are removing quotes, or stripping an unknown number of spaces leading into the data of interest. This can be done pretty easily with other methods such as awk or…

  • Zombie Process: Killing the Undead

    Is your Ubuntu MOTD warning you of a zombie process? Welcome to Ubuntu 11.10 (GNU/Linux 3.0.0-20-server x86_64) * Documentation: https://help.ubuntu.com/11.10/serverguide/C System information as of Thu Jun 28 18:36:57 EDT 2012 System load: 0.0 Processes: 94 Usage of /: 68.2% of 1.79TB Users logged in: 1 Memory usage: 29% IP address for eth0: 10.0.0.10 Swap usage:…

  • Access an APC AP5456 IP Gateway for Analog KVM in Linux

    Access an APC AP5456 IP Gateway for Analog KVM in Linux

    I recently wrote about running an ActiveX component without Internet Explorer. I used that technique to come up with a shell script front-end for downloading, unpacking and running an executable in Wine for accessing an APC IP KVM (model AP5456). Here is the results of that effort. At a minimum the script requires Wine and…

  • Bash Snippet: URL Encoding

    Bash Snippet: URL Encoding

    One approach would be to encode everything, but the approach I took was to just encode things I thought might be problematic to pass over the query string. URL (a.k.a percent) encoding of a string in bash: urlencode () {         tab="`echo -en "\x9"`"         i="$@"      …

  • Bash Snippet: Calculating the Distance Between 2 Coordinates

    Bash Snippet: Calculating the Distance Between 2 Coordinates

    I have a tendency to do things in bash that I’d probably be better off doing in perl or python. Although bash may have super powers, math is not one of them, and so like my last post this script also requires bc. I’ll try and keep these code snippet posts short and sweet, and…

  • Bash Snippet: HTML &#code; decoder

    Bash Snippet: HTML &#code; decoder

    A short and simple way to decode HTML decimal (and hex) character codes in bash. html_decode () {     html_encoded="$1"     html_encoded=${html_encoded//&#/ }     html_encoded=(`echo $html_encoded`)     for html_dec in ${html_encoded[@]}     do         html_dec="${html_dec//X/x}"         html_dec="${html_dec//;/}"         if [ "${html_dec:0:1}"…