Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
vysecurity committed Jan 12, 2024
1 parent 50bde1d commit 42f773a
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 47 deletions.
Binary file added ipfuscator
Binary file not shown.
118 changes: 118 additions & 0 deletions ipfuscator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"flag"
"fmt"
"math/rand"
"regexp"
"strconv"
"strings"
"time"
)

var version = "1.0.0"

func main() {
ipPtr := flag.String("ip", "", "The IP to perform IPFuscation on")
flag.Parse()
if *ipPtr == "" {
fmt.Println("Please specify ip using -ip flag.")
return
}

showBanner()
ip := *ipPtr
if checkIP(ip) {
fmt.Printf("\nIP address: \t%s", ip)
printOutput(ip)
} else {
fmt.Printf("[!] Invalid IP format: %s\n", ip)
}
}

func showBanner() {
fmt.Println("IPFuscator")
fmt.Println("Author: Vincent Yiu (@vysecurity)")
fmt.Println("https://www.github.com/vysecurity/IPFuscator")
fmt.Printf("Version: %s\n", version)
fmt.Println()
}

func checkIP(ip string) bool {
match, _ := regexp.MatchString(`(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})`, ip)
if match {
parts := strings.Split(ip, ".")
if len(parts) == 4 {
for _, p := range parts {
if num, err := strconv.Atoi(p); err != nil || num < 0 || num > 255 {
return false
}
}
return true
}
}
return false
}

func printOutput(ip string) {
parts := strings.Split(ip, ".")

dec := [4]int{}
hex := [4]string{}
oct := [4]string{}
for i := 0; i < 4; i++ {
dec[i], _ = strconv.Atoi(parts[i])
hex[i] = strconv.FormatInt(int64(dec[i]), 16)
oct[i] = strconv.FormatInt(int64(dec[i]), 8)
}

decimal := dec[0]*16777216 + dec[1]*65536 + dec[2]*256 + dec[3]
fmt.Printf("\nDecimal:\t%d", decimal)
fmt.Printf("\nHexadecimal:\t%x", decimal)
fmt.Printf("\nOctal:\t\t%o", decimal)

fmt.Printf("\n\nFull Hex:\t%s", strings.Join(hex[:], "."))
fmt.Printf("\nFull Oct:\t%s", strings.Join(oct[:], "."))

fmt.Println("\n\nRandom Padding: ")

rand.Seed(time.Now().UnixNano())
randhex := [4]string{}
randoct := [4]string{}
for i := 0; i < 4; i++ {
randhex[i] = fmt.Sprintf("%x", dec[i]*int(rand.Intn(30)+1))
randoct[i] = fmt.Sprintf("%o", dec[i]*int(rand.Intn(30)+1))
}

fmt.Printf("\nHex:\t\t%s", strings.Join(randhex[:], "."))
fmt.Printf("\nOct:\t\t%s", strings.Join(randoct[:], "."))

fmt.Println("\n\nRandom base:")
for i := 0; i < 5; i++ {
randbase := [4]string{}
for j := 0; j < 4; j++ {
choices := [3]string{parts[j], hex[j], oct[j]}
randbase[j] = choices[rand.Intn(3)]
}
fmt.Printf("\n#%d:\t\t%s", i+1, strings.Join(randbase[:], "."))
}

fmt.Println("\n\nRandom base with random padding:")
for i := 0; i < 5; i++ {
randbase := [4]string{}
for j := 0; j < 4; j++ {
switch rand.Intn(3) {
case 0:
randbase[j] = parts[j]
case 1:
randbase[j] = fmt.Sprintf("%x",
dec[j]*int(rand.Intn(30)+1))
default:
randbase[j] = fmt.Sprintf("%o",
dec[j]*int(rand.Intn(30)+1))
}
}
fmt.Printf("\n#%d:\t\t%s", i+1, strings.Join(randbase[:], "."))
}
fmt.Println()
}
138 changes: 91 additions & 47 deletions ipfuscator.py
Original file line number Diff line number Diff line change
@@ -1,101 +1,145 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from argparse import ArgumentParser
import struct
import re, random


__version__ = '1.0.0'
__version__ = '0.1.0'


def get_args():
parser = ArgumentParser()
parser.add_argument('ip', help='The IP to perform IPFuscation on')
parser.add_argument('-o', '--output', help='Output file')
return parser.parse_args()


def banner():
print("IPFuscator")
print("Author: Vincent Yiu (@vysecurity)")
print("https://www.github.com/vysecurity/IPFuscator")
print("https://www.github.com/vysec/IPFuscator")
print("Version: {}".format(__version__))
print("")


def check_ip(ip):
m = re.fullmatch('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip)

def checkIP(ip):
m = re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\Z',ip)

if m:
# Valid IP format
parts = ip.split('.')
if len(parts) == 4 and all(0 <= int(p) <= 255 for p in parts):
if len(parts) == 4:
# Valid IP
for i in parts:
if int(i) > 255 or int(i) < 0:
return False
return True
return False

else:
return False
else:
return False

def print_output(ip):
def printOutput(ip):
parts = ip.split('.')

decimal = int(parts[0]) * 16777216 + int(parts[1]) * 65536 + int(parts[2]) * 256 + int(parts[3])
print("\nDecimal:\t{}".format(decimal))
print("")

print("Decimal:\t{}".format(decimal))
#hexadecimal = "0x%02X%02X%02X%02X" % (int(parts[0]), int(parts[1]), int(parts[2]), int(parts[3]))
print("Hexadecimal:\t{}".format(hex(decimal)))
print("Octal:\t\t{}".format(oct(decimal)))

hexparts = [hex(int(i)) for i in parts]
octparts = [oct(int(i)) for i in parts]
#octal = oct(decimal)
print("Octal:\t\t0{}".format(oct(decimal)[2:]))

print("")

hexparts = []
octparts = []

print ("\nFull Hex:\t{}".format('.'.join(hexparts)))
print ("Full Oct:\t{}".format('.'.join(octparts)))
for i in parts:
hexparts.append(hex(int(i)))
octparts.append("0" + oct(int(i))[2:])

print ("\nRandom Padding: ")
print("Full Hex:\t{}".format('.'.join(hexparts)))
print("Full Oct:\t{}".format('.'.join(octparts)))

randhex = '.'.join([i.replace('0x','0x' + '0' * random.randint(1,30)) for i in hexparts])
print ("Hex:\t{}".format(randhex))
print("")
print("Random Padding: ")

randoct = '.'.join(['0' * random.randint(1,30) + i for i in octparts])
print ("Oct:\t{}".format(randoct))
randhex = ""

print ("\nRandom base:")
for i in hexparts:
randhex += i.replace('0x','0x' + '0' * random.randint(1,30)) + '.'

randbase = []
for _ in range(5):
randbaseval = []
for i in range(4):
choices = [parts[i], hexparts[i], octparts[i]]
randbaseval.append(random.choice(choices))
randbase.append('.'.join(randbaseval))
randhex = randhex[:-1]
print("Hex:\t{}".format(randhex))

for i, base in enumerate(randbase):
print("#{}:\t{}".format(i+1, base))
randoct = ""
for i in octparts:
randoct += '0' * random.randint(1,30) + i + '.'

print ("\nRandom base with random padding:")
randoct = randoct[:-1]

print("Oct:\t{}".format(randoct))

print("")
print("Random base:")

randbase = []
for _ in range(5):
randbaseval = []
for i in range(4):
val = random.choice([0, 1, 2])

count = 0
while count < 5:
randbaseval = ""
for i in range(0,4):
val = random.randint(0,2)
if val == 0:
randbaseval.append(parts[i])
# dec
randbaseval += parts[i] + '.'
elif val == 1:
randbaseval.append(hexparts[i].replace('0x', '0x' + '0' * random.randint(1,30)))
# hex
randbaseval += hexparts[i] + '.'
else:
randbaseval.append('0' * random.randint(1,30) + octparts[i])
randbase.append('.'.join(randbaseval))
randbaseval += octparts[i] + '.'
# oct
randbase.append(randbaseval[:-1])
print("#{}:\t{}".format(count+1, randbase[count]))
count += 1

print("")
print("Random base with random padding:")

for i, base in enumerate(randbase):
print("#{}:\t{}".format(i+1, base))
randbase = []

count = 0
while count < 5:
randbaseval = ""
for i in range(0,4):
val = random.randint(0,2)
if val == 0:
# dec
randbaseval += parts[i] + '.'
elif val == 1:
# hex
randbaseval += hexparts[i].replace('0x', '0x' + '0' * random.randint(1,30)) + '.'
else:
randbaseval += '0' * random.randint(1,30) + octparts[i] + '.'
# oct
randbase.append(randbaseval[:-1])
print("#{}:\t{}".format(count+1, randbase[count]))
count += 1


def main():
banner()

args = get_args()

if check_ip(args.ip):
if checkIP(args.ip):
print("IP Address:\t{}".format(args.ip))
print_output(args.ip)
printOutput(args.ip)
else:
print("[!] Invalid IP format: {}".format(args.ip))


if __name__ == '__main__':
main()
main()
Loading

0 comments on commit 42f773a

Please sign in to comment.