We are closing registration and public forum view to Paid & Private in 16 days! CLICK HERE to register FREE.
 
Create an account  

For users privacy, our last domains: CarderHack.com and OmertaHack.net are moved to CardingTeam.ws

Deposit & Withdraw | About Verified Sellers and Escrow | Advertise | Scam Report | Tracking Number Details | ICQ: 717039384

carding forums carding forums
carding forums carding forums
carding forums Paid adv expire in 48 days
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 
►► Bit Manipulations ◄◄

#1
[0x01] Bit Manipulation:
Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word or string. Programming tasks that require bit manipulation include low-level device control. error detection and correction algorithms, data compression, encryption algorithms, and optimization. Code that does bit manipulation makes of of the bitwise operations: AND, OR, XOR, NOT, and bit shifts. This can be quite useful for those who are into low-level exploitation when creating and optimizing your asm, and shell code to contains the least number of bytes. So Bit manipulation can be done in just about any language, but for this tutorial I will be doing various bit manipulations in the python programming language.

[0x02] Manipulations:

[*] Find Bytes of Hex String!
Okay so we want to find how many bytes Phizo's hex string contains. Python code below

Code:
; Code Provided BY Phizo; setuid(0); execve("/bin/sh", 0, 0); exit(0);; priv9 indishell r00tkit!! say no to b!g br0th3r - #FreeKevinsection .text         global _start_start:         push 0x17         pop eax                         ; syscall # for sys_setuid()         xor ebx,ebx             ; uid_t uid = 0 (root)         int 0x80                        ; poke the kernel         push 0x68732f78         ; 'hs/x'         shr dword[esp],8        ; shift ECX right by 8 bits - discarding 0x78 & padding 0x00 ('0\hs/')         push 0x6e69622f         ; 'nib/'         push 0x0B         pop eax                         ; syscall # for sys_execve()         mov ebx,esp             ; char *filename = "/bin/sh\0"         xor ecx,ecx             ; char argv[]   = NULL         xor edx,edx             ; char envp[]   = NULL         int 0x80                        ; poke the kernel         push 0x01         pop eax                         ; syscall # for sys_exit()         xor ebx,ebx             ; int error_code = 0         int 0x80                        ; poke the kernel
Hex
Code:
(shellcode):\x6a\x17\x58\x31\xdb\xcd\x80\x68\x78\x2f\x73\x68\xc1\x2c\x24\x08\x68\x2f\x62\x69​\x6e\x6a\x0b\x58\x89\xe3\x31\xc9\x31\xd2\xcd\x80\x6a\x01\x58\x31\xdb\xcd\x80

# coding : utf-8hex = r"\x6a\x17\x58\x31\xdb\xcd\x80\x68\x78\x2f\x73\x68\xc1\x2c\x24\x08\x68\x2f\x62\x69​\x6e\x6a\x0b\x58\x89\xe3\x31\xc9\x31\xd2\xcd\x80\x6a\x01\x58\x31\xdb\xcd\x80"hex.decode('string-escape')counter = hex.count('x')print ("Number of Bytes: %s" % (counter))

We declare the hex value as a string, using r (raw string literal) to get the raw value of the hex and not have the interpreter parse the backslashes. Also declare the encoding "utf-8", hex.decode() to decode the encoding, hex.count() to count the number of occurrences of 'x' in the hex string. Then using string formatting to print an integer after a string. %s is a value holder for the statement after %, which is the counter string.


OUTPUT:Number of Bytes: 39


[*] Binary String to Integer!
Convert a binary string to integer.

input = raw_input('Enter Binary String: ')print 'Interger is: %s' % (int(input, 2))

Simple version of the code above, or rather the main part is: int(00100001, 2). Where 00100001 can be any binary string of your choice. You can test this in the python IDLE gui. The above code just takes the raw input of the string input. raw_input prompts "Enter Binary String" in your terminal or cmd and whatever you type in will be the value of the input string. Then once again using string formatting we make %s equal to int(input, 2). input being whatever you entered, and then 2 being the base. The int() function just validates that the final product will be an integer.

OUPUT:Enter Binary String: 00100001Integer is: 33


[*] Binary String to Hex String!
Convert a binary string to a hex string.

input = raw_input('Enter Binary String: ')print 'Hex String is: 0x%x' % (int(input, 2))

Should not have to discuss the above code because it is pretty much the Binary to Integer code. The only difference here is adding 0x to the prefix of the output to represent hex value and the '%x' integer presentation. %x is for the hex format to as where %s is the string format and a string presentation. Note: You dont need to use x8 bits like above. Example below.

OUTPUT:Enter Binary String: 11111111Hex String is: 0xff


[*] Binary String to Character!
Convert Binary string to Character.

print '8 bits Max'input = raw_input('Enter Binary String: ')print 'Character String is: %s' % chr(int(input, 2))

Simple version of this in IDLE would be, chr(int(1110110, 2)). Which you can replace 1110110 with any 8 bit binary string of your liking. The above code, just takes input variable to the base of 2, converts it to an integer then uses the chr() function to turn the integer into a corresponding character. Example below.

OUTPUT:Enter Binary String: 1110110Character String is: v


[*] Hex String to Integer!
Convert Hex string to Integer.

input = raw_input('Enter Hex String: ')print 'Integer of Hex is: %s' % int(input, 16)

Simple version of this in IDLE would be, int(0xff, 16). The above code take input to the base of 16 and takes the integer value with the int() function. Example below.

Enter Hex String: 0xffInteger of Hex is: 255



[*] Character to Integer!
Convert Single Character to Integer value.

input = raw_input('Enter Character: ')print 'Integer String is: %s' % ord(input)

Simple version of this can be done in IDLE: ord('u'). Replacing u with any character of your choice. The above code uses the ord() function, which returns the integer value of a character. This is also equivalent to converting an 8 bit binary string to an integer. Like so: int('01110101', 2) = 117. Then validate this, we can take the binary string and convert it into a character and then using the above code see if the integer value of that character is equivalent to 117. chr(int('01110101', 2)) = u. Place 'u' into the above code.

OUTPUT:Enter Character: uInteger String is: 117


[*] Binary String to Single Character!
Convert Binary string to single character, this was discussed a bit above, but lets look at the code.

input = raw_input('Enter Binary String: ')print 'Single Character is: %s' % chr(int(input, 2))

Like discussed above in the Character to Integer section, we take the int() value of input to the base of 2 and then take that value to convert it to the corresponding character using the chr() function. Example below, using the u example we discussed earlier.

OUTPUT:Enter Binary String: 01110101Single Character is: u


[*] Individual Bits:
Individual bits of Integers.

input = raw_input('Enter Integer: ')print 'Individual Bit: %s' % int(1 << int(input))

The above code take the integer value of input and uses the << bitwise operator to compare the value to 1. This a small example of bit shifting. The << is the Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. Example below:

OUTPUT:Enter Integer: 2Individual Bit: 4


[*] Integer to Binary String!
Convert Integer to Binary string.

input = raw_input('Enter Integer: ')print 'Binary String is: %s' % bin(int(input))print "Binary String to 0&1's: %s" % bin(int(input))[2:]

The above code has to values returned. Dont freak, its just a clean up of the first value returned, to just output straight binary. Here we are using the built in bin() function to convert the integer value of input into binary. The bin() function does this all for us.

OUTPUT:Enter Integer: 117Binary String is: 0b1110101Binary String to 0&1's: 1110101# The [2:] removes the first two character which are 0b. But in reality the 0 is needed.So the actual Binary would be: 01110101. Adding the 0 back.


[*] Bit Length Count of Python Integer!
Get the Bit length count of a integer.

input = int(raw_input('Enter Integer: '))print 'Bit Count Length Of Integer: %s' % input.bit_length()

The above code, takes the int value of our raw_input() in the input string. So whatever is typed is parsed as an integer. Then we just simply use the built in bit_length() function. Applying it to our input string like so, input.bit_length(). Example Below:

Enter Integer: 8Bit Count Length Of Integer: 4


[*] Some other awesome tricks you can do in python that I dont feel like discussing but Im sure you python guys will understand.:

[*] Size of a integer of an arbitrary base:

def f(num, base=10):o = 0while num:         o+= 1         num/= basereturn odef bitLen(int_type):length = 0while (int_type):         int_type >>= 1         length += 1return(length)


[*] Binary Prefix:

def binary_prefix(value, binary=True):"""Parameters:- `value`: numeric type to trim down- `binary`: use binary (ICE) or decimal (SI) prefix"""SI = 'kMGTPEZY'unit = 1024. if binary else 1000.for i in range(-1, len(SI)):         if abs(value) < unit:                 break         value/= unitreturn (value, '' if i<0 else (SI[i].upper() + 'i' if binary else SI[i]))


   [0x03] Above Techniques in one script:
   Just added command arguments. You know how it is.

Code:
   # coding: utf-8import sysimport mathfor arg in sys.argv:if arg in ("--help"):printprint 'Usage Menu:'printprint '########################################################'printprint '--hex-to-byte     | Find Bytes of Hex String!'print '--bin-to-integer | Binary String to Integer!'print '--bin-to-hex      | Binary String to Hex String!'print '--bin-to-char     | Binary String to Character!'print '--hex-to-int      | Hex String to Integer!'print '--char-to-int     | Character to Integer!'print '--bin-to-sing-char | Binary String to String Character!'print '--indiv-bits      | Individual Bits Of Integer!'print '--int-to-bin      | Integer to Binary String!'print '--bit-len-count   | Bit Length Count of Integer!'printprint '########################################################'for arg in sys.argv:if arg in ("--hex-to-byte"):# replace hex stringhex = r"\x6a\x17\x58\x31\xdb\xcd\x80\x68\x78\x2f\x73\x68\xc1\x2c\x24\x08\x68\x2f\x62\x69​\x6e\x6a\x0b\x58\x89\xe3\x31\xc9\x31\xd2\xcd\x80\x6a\x01\x58\x31\xdb\xcd\x80"hex.decode('string-escape')counter = hex.count('x')print ("Number of Bytes: %s" % (counter))for arg in sys.argv:if arg in ("--bin-to-integer"):input = raw_input('Enter Binary String: ')print 'Integer is: %s' % (int(input, 2))for arg in sys.argv:if arg in ("--bin-to-hex"):input = raw_input('Enter Binary String: ')print 'Hex String is: 0x%x' % (int(input, 2))for arg in sys.argv:if arg in ("--bin-to-char"):print "8 Bits Max"input = raw_input('Enter Binary String: ')print 'Character String is: %s' % chr(int(input, 2))for arg in sys.argv:if arg in ("--hex-to-int"):input = raw_input('Enter Hex String: ')print 'Hex String to Integer!'print 'Integer of Hex is: %s' % int(input, 16)for arg in sys.argv:if arg in ("--char-to-int"):print 'Single Character to Integer!'input = raw_input('Enter Character: ')print 'Integer String is: %s' % ord(input)for arg in sys.argv:if arg in ("--bin-to-sing-char"):print 'Binary to Single Character!'input = raw_input('Enter Binary String: ')print 'Single Character is: %s' % chr(int(input, 2))for arg in sys.argv:if arg in ("--indiv-bits"):print 'Individual Bits, Enter an Integer..1,2,3,etc..'input = raw_input('Enter Bit: ')print 'Individual Bit: %s' % int(1 << int(input))for arg in sys.argv:if arg in ("--int-to-bin"):print 'Integer to Binary String!'input = raw_input('Enter Integer: ')print 'Binary String is: %s' % bin(int(input))print "Binary String to 0&1's: %s" % bin(int(input))[2:]for arg in sys.argv:if arg in ("--bit-len-count"):print 'Bit Length Count of Python Integer!'input = int(raw_input('Enter Integer: '))print 'Bit Count Length of Integer: %s' % input.bit_length()

[0x04] Conclusion:
Well there you go. Some basic bit manipulations all you low-level beginners can look at and use if needed. Hope you guys enjoy this Shy anything that you think needs to be added just post it and Ill add it. Thanks for viewing.
Reply
Paid adv. expire in 47 days
CLICK to buy Advertisement !

    Verified & Trusted HACKED Payza, PayPal, Ukash, Ucard, EgoPay, Skrill - TRANSFER [Escrow accepted]




Forum Jump: