Skip to content

Commit 23c1f8d

Browse files
authored
Added PatternCreate and PatternOffset
1 parent 230d4fb commit 23c1f8d

File tree

1 file changed

+323
-0
lines changed

1 file changed

+323
-0
lines changed

hacklib.py

+323
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
import socket, httplib, threading, time, urllib2, os
2222
from Queue import Queue
23+
import logging
24+
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) # Fixes scapy logging error
25+
from scapy.all import * # Required for the Probe Request Class
26+
from string import ascii_uppercase, ascii_lowercase, digits # Import for PatternCreate and PatternOffset
2327

2428
class FTPAuth(object):
2529
'''FTP login and command handler.
@@ -701,6 +705,325 @@ def userInterface():
701705
print 'Proxy connected.'
702706
time.sleep(2)
703707
pass
708+
"""
709+
710+
This Class Mangles Words specified by the user
711+
712+
Example:
713+
714+
Test = hacklib.Mangle("Test", 1, 10, 1996, 2016)
715+
716+
Test.Leet()
717+
718+
Output: T3st
719+
720+
"""
721+
722+
class Mangle:
723+
724+
def __init__(self, text, num1, num2, year1, year2):
725+
726+
self.num1 = num1
727+
self.num2 = num2
728+
self.year1 = year1
729+
self.year2 = year2
730+
self.text = text
731+
732+
733+
def Numbers(self):
734+
735+
for x in self.text.split():
736+
737+
for i in range(self.num1, self.num2):
738+
739+
print ("%s" + "%s") % (x, i)
740+
print ("%s" + "%s") % (i, x)
741+
742+
def Years(self):
743+
744+
for x in self.text.split():
745+
746+
for i in range(self.year1, self.year2):
747+
748+
print ("%s" + "%s") % (x, i)
749+
print ("%s" + "%s") % (i, x)
750+
751+
752+
def UniqueNum(self):
753+
754+
for x in self.text.split():
755+
756+
for i in range(self.num1, self.num2):
757+
758+
print ("%s" + "%s" + "%s") % (x, x, i)
759+
760+
761+
def UniqueYears(self):
762+
763+
for x in self.text.split():
764+
765+
for i in range(self.year1, self.year2):
766+
767+
print ("%s" + "%s" + "%s") % (x, x, i)
768+
769+
770+
771+
def FirstLetterCapNum(self):
772+
773+
for x in self.text.split():
774+
775+
for i in range(self.num1, self.num2):
776+
777+
print ("%s" + "%s") % (x.capitalize(), i)
778+
print ("%s" + "%s") % (i, x.capitalize())
779+
780+
def Caps(self):
781+
782+
for x in self.text.split():
783+
784+
print x.capitalize()
785+
786+
787+
def UniqueCaps(self):
788+
789+
for x in self.text.split():
790+
791+
print ("%s" + "s") % (x.capitalize(), x.capitalize())
792+
793+
794+
795+
def CapandYears(self):
796+
797+
for x in self.text.split():
798+
799+
for i in range(self.year1, self.year2):
800+
801+
print ("%s" + "%s") % (x.capitalize(), i)
802+
print ("%s" + "%s") % (i, x.capitalize())
803+
804+
805+
def Leet(self):
806+
807+
for x in self.text.split():
808+
print x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8")
809+
810+
811+
812+
def LeetCap(self):
813+
814+
for x in self.text.split():
815+
print x.capitalize().replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8")
816+
817+
818+
819+
def LeetYears(self):
820+
821+
for x in self.text.split():
822+
823+
for i in range(self.year1, self.year2):
824+
825+
print ("%s" + "%s") % (x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8"), i)
826+
print ("%s" + "%s") % (i, x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8"))
827+
828+
829+
def LeetNumbers(self):
830+
831+
for x in self.text.split():
832+
833+
for i in range(self.num1, self.num2):
834+
835+
print ("%s" + "%s") % (x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8"), i)
836+
print ("%s" + "%s") % (i, x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8"))
837+
838+
839+
def UniqueLeet(self):
840+
841+
for x in self.text.split():
842+
843+
print ("%s" + "%s") % (x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8"),(x.replace("e", "3").replace("i", "1").replace("O", "0").replace("I", "1").replace("E", "3").replace("o", "0").replace("l", "1").replace("L", "1").replace("g", "9").replace("G", "6").replace("b", "8").replace("B", "8")))
844+
845+
846+
847+
def Reverse(self):
848+
849+
for x in self.text.split():
850+
851+
print x[::-1]
852+
853+
854+
def ReverseCap(self):
855+
856+
for x in self.text.split():
857+
print x[::-1].capitalize()
858+
859+
860+
861+
def ReverseNum(self):
862+
863+
for x in self.text.split():
864+
865+
for i in range(self.num1, self.num2):
866+
867+
print ("%s" + "%s") % (x[::-1], i)
868+
print ("%s" + "%s") % (i, x[::-1])
869+
870+
871+
872+
def ReverseYears(self):
873+
874+
for x in self.text.split():
875+
876+
for i in range(self.year1, self.year2):
877+
878+
print ("%s" + "%s") % (x[::-1], i)
879+
print ("%s" + "%s") % (i, x[::-1])
880+
881+
882+
def ReverseUnique(self):
883+
884+
for x in self.text.split():
885+
886+
print x[::-1] + x[::-1]
887+
888+
'''
889+
This Classes Dectects Probe Requests from Wireless Devices.
890+
891+
Example:
892+
893+
Probe = Proberequests("wlan0")
894+
895+
Probe.startSniff()
896+
897+
'''
898+
899+
class Proberequests:
900+
901+
global probeReqs
902+
903+
probeReqs = []
904+
905+
def __init__(self, interface):
906+
907+
self.interface = interface
908+
909+
def sniffProbe(self, p):
910+
911+
if p.haslayer(Dot11ProbeReq):
912+
netName = p.getlayer(Dot11ProbeReq).info
913+
if netName not in probeReqs:
914+
probeReqs.append(netName)
915+
print '[!] Detected New Probe Request: '
916+
print "[+] ESSID: " + netName + " BSSID: " + p.addr2
917+
918+
def startSniff(self):
919+
920+
print "[+] Scanning...\n"
921+
922+
sniff(iface=self.interface, prn=self.sniffProbe)
923+
924+
"""
925+
926+
This class creates a unique pattern of 20280 characters.
927+
928+
This is a replica of the metasploit tool called pattern_create.rb
929+
930+
Example:
931+
932+
patternTest = PatternCreate(1000)
933+
934+
patternTest.generate()
935+
936+
Creates a unique pattern of 1000 characters.
937+
938+
"""
939+
940+
class PatternCreate:
941+
942+
global MAX_PATTERN_LENGTH
943+
944+
MAX_PATTERN_LENGTH = 20280
945+
946+
def __init__(self, length):
947+
948+
self.length = length
949+
950+
def generate(self):
951+
952+
output = []
953+
954+
"""
955+
Generate a pattern of a given length up to a maximum
956+
of 20280 - after this the pattern would repeat
957+
"""
958+
if self.length >= MAX_PATTERN_LENGTH:
959+
raise MaxLengthException('ERROR: Pattern length exceeds maximum of %d' % MAX_PATTERN_LENGTH)
960+
961+
pattern = ''
962+
for upper in ascii_uppercase:
963+
for lower in ascii_lowercase:
964+
for digit in digits:
965+
if len(pattern) < self.length:
966+
pattern += upper+lower+digit
967+
else:
968+
out = pattern[:self.length]
969+
970+
output.append(out)
971+
972+
print str(output)[1:-1].replace("'", "")
973+
974+
975+
"""
976+
977+
This class finds the offset from the PatternCreate class.
978+
979+
This is a replica of the metasploit tool called pattern_offset.rb
980+
981+
Example:
982+
983+
offset = PatternOffset("Aw1A")
984+
985+
offset.find()
986+
987+
Finds offset of Aw1A.
988+
989+
Output: [+] Offset: 663
990+
991+
"""
992+
993+
994+
class PatternOffset:
995+
996+
def __init__(self, search_pattern):
997+
998+
self.search_pattern = search_pattern
999+
1000+
def find(self):
1001+
1002+
offset = []
1003+
1004+
needle = self.search_pattern
1005+
1006+
try:
1007+
if needle.startswith('0x'):
1008+
# Strip off '0x', convert to ASCII and reverse
1009+
needle = needle[2:]
1010+
needle = bytes.fromhex(needle).decode('ascii')
1011+
needle = needle[::-1]
1012+
except TypeError as e:
1013+
print('Unable to convert hex input:', e)
1014+
sys.exit(1)
1015+
1016+
haystack = ''
1017+
for upper in ascii_uppercase:
1018+
for lower in ascii_lowercase:
1019+
for digit in digits:
1020+
haystack += upper+lower+digit
1021+
found_at = haystack.find(needle)
1022+
if found_at > -1:
1023+
1024+
offset = found_at
1025+
1026+
print "[+] Offset: " + str(offset)
7041027

7051028
if __name__ == '__main__':
7061029
userInterface()

0 commit comments

Comments
 (0)