homepage
Open menu Go one level top
  • Train and Certify
    • Get Started in Cyber
    • Courses & Certifications
    • Training Roadmap
    • Search For Training
    • Online Training
    • OnDemand
    • Live Training
    • Summits
    • Cyber Ranges
    • College Degrees & Certificates
    • NICE Framework
    • DoDD 8140
    • Specials
  • Manage Your Team
    • Overview
    • Security Awareness Training
    • Voucher Program
    • Private Training
    • Workforce Development
    • Skill Assessments
    • Hiring Opportunities
  • Resources
    • Overview
    • Reading Room
    • Webcasts
    • Newsletters
    • Blog
    • Tip of The Day
    • Posters
    • Top 25 Programming Errors
    • The Critical Security Controls
    • Security Policy Project
    • Critical Vulnerability Recaps
    • Affiliate Directory
  • Focus Areas
    • Blue Team Operations
    • Cloud Security
    • Digital Forensics & Incident Response
    • Industrial Control Systems
    • Leadership
    • Offensive Operations
  • Get Involved
    • Overview
    • SANS Community
    • CyberTalent
    • Work Study
    • Instructor Development
    • Sponsorship Opportunities
    • COINS
  • About
    • About SANS
    • Why SANS?
    • Instructors
    • Cybersecurity Innovation Awards
    • Contact
    • Frequently Asked Questions
    • Customer Reviews
    • Press Room
  • Log In
  • Join
  • Contact Us
  • SANS Sites
    • GIAC Security Certifications
    • Internet Storm Center
    • SANS Technology Institute
    • Security Awareness Training
  • Search
  1. Home >
  2. Blog >
  3. Plundering Windows Account Info via **Authenticated** SMB Sessions
370x370_Ed-Skoudis.jpg
Ed Skoudis

Plundering Windows Account Info via **Authenticated** SMB Sessions

July 24, 2013

I absolutely adore the Server Message Block (SMB) protocol. Sure, it's ugly and bewilderingly complex. But, what I love is the raw power SMB provides for manipulating Windows environments during a penetration test. Via SMB, you can remotely access file shares, the registry, services, domain authentication, and much more! What's not to like? Well, the ugliness and complexity, but we can overlook those with a few good tools, right?

One of the best tools for thoroughly plundering a Windows target via SMB is the Linux rpcclient command, part of the Samba suite. The rpcclient program was originally designed for troubleshooting and debugging Windows and Linux Samba daemon configurations, but we can leverage its capabilities in a penetration test (or even a vulnerability assessment or audit) to gather some awesome info.

Chris Gates, at the Carnal0wnage blog, posted a few excellent articles (including this one here and another one here) about using rpcclient to interrogate target Windows machines across NULL SMB sessions. A NULL SMB session has a blank user name and a blank password. However, most modern Windows systems by default prohibit enumerating detailed user information across a NULL SMB session (controlled by the HKLM\System\CurrentControlSet\Control\Lsa\RestrictAnonymous, RestrictAnonymousSAM, and EveryoneIncludesAnonymous registry keys).

Some pen testers I've met think that because NULL sessions are increasingly extinct, stuff like rpcclient isn't useful. But, hey? as long as you have just one user name and its associated password (local or domain) for the target environment, you can make AUTHENTICATED SMB sessions (non-NULL). Even if your user and password are NOT in the admin group or domain admin group, you can still get a HUGE amount of information via an authenticated, non-admin SMB session to a target machine in the environment, plundering all kinds of stuff, including user names, group memberships, Security Identifiers (SIDs), and even last logon events. I'd like to show you how, as well as how a defender can squelch incoming SMB sessions in real-time on a Windows box.

First, you'll need to get a user name and password. In a crystal box penetration test or an internal audit, you may be given one by target system personnel as part of your planning activities. If not, try to ask for one, explaining that you want to see if this limited user can break out of their constraints and take over the target environment, modeling what would happen if an insider tries to attack, or an outsider exploits an employee's account.

If those arguments still don't get you a non-admin user name and password, you could try to do some brute force guessing, using a tool like Metasploit's auxiliary/scanner/smb/smb_login module, which can be configured to do guessing of passwords from a list.

Once you have a user name and password and open SMB access of a target Windows client or server over TCP port 445, you can use rpcclient to open an authenticated SMB session to a target machine by running the following command on your Linux system (rpcclient is built into many Linux distros by default):

$ rpcclient —U <username> <winipaddr>

If you had used a NULL Session, you would have entered a username of "". But, instead, use a real user name (which doesn't have to be in the admin group). When prompted for the password, enter it, and you'll see the funky rpcclient prompt (I say it is funky, because of it's $> notation):

rpcclient $>

Now, you have a whole freaking candy store of yummy SMB commands at your fingertips. Just type "help" to see all of the over 100 commands. Yeouch. Nice.

(I have seen, on rare occasions, rpcclient refuse to connect unless it has the name of the target Windows machine inside of /etc/hosts. If it doesn't work, simply append into /etc/hosts a line that has the IP address of the target Windows machine and the hostname of that machine.)

I'd like to show you some of the most useful commands within rpcclient. First off, let's get the version of the target Windows machine:

rpcclient $> srvinfo

10.10.76.1     Wk Sv NT PtB
platform_id     :       500
os version      :       6.2
server type     :       0x11003

You can look up the different server version types here. As we can see, we've got an OS version of 6.2, so it's a Windows 8 or Windows Server 2012 machine. In this case, it just so happens to be Windows 8.

Now, let's slurp up some users. Start by typing "enum" at the prompt and hitting <tab><tab>:

rpcclient $> enum

enumalsgroups  enumdomains    enumdrivers    enumkey     enumprivs
enumdata       enumdomgroups  enumforms      enumports   enumtrust
enumdataex     enumdomusers   enumjobs       enumprinter

Nice! On most Linuxes, we have tab auto-complete of commands, which extends into rpcclient commands. And, yes, this little rpcclient shell can clear the screen with a CTRL-L. To enumerate users, run the following command:

rpcclient $> enumdomusers

user:[Administrator] rid:[0x1f4]
user:[Fred] rid:[0x3e9]
user:[Guest] rid:[0x1f5]
user:[HomeGroupUser$] rid:[0x3eb]
user:[lab] rid:[0x3ec]
user:[stuff] rid:[0x3f1]
user:[test] rid:[0x3f5]

Here, we can see the user names as well as their RID (the suffix of their SID) in hexadecimal form.

Now, let's look at groups. For this, we'll first enumerate domain groups (with "enumalsgroups domain") and then builtin groups (with "enumalsgroups builtin"). The union of these two sets are the groups that this target knows about. By the way, the "als" between enum and groups in this command refers to "aliases". Windows treats some group names as aliases.

rpcclient $> enumalsgroups domain
group:[HomeUsers] rid:[0x3ea]
group:[WinRMRemoteWMIUsers__] rid:[0x3e8]

rpcclient $> enumalsgroups builtin
group:[Administrators] rid:[0x220]
group:[Backup Operators] rid:[0x227]
group:[Cryptographic Operators] rid:[0x239]
group:[Event Log Readers] rid:[0x23d]
group:[Guests] rid:[0x222]
group:[Hyper-V Administrators] rid:[0x242]
group:[IIS_IUSRS] rid:[0x238]
group:[Power Users] rid:[0x223]
group:[Remote Desktop Users] rid:[0x22b]
group:[Remote Management Users] rid:[0x244]
group:[Users] rid:[0x221]

Again, we see the group name and the RID for each group.

To determine a full SID, you could run the "lookupnames" command. Here, I'll do it for the administrator account and then the administrators group:

rpcclient $> lookupnames administrators
administrators S-1-5-32-544 (Local Group: 4)

rpcclient $> lookupnames administrator
administrator S-1-5-21-728759338-17244630-2184799192-500 (User: 1)

There is likewise a lookupsids command that converts a SID to a username.

Now, wanna see something really cool? We can use the queryuser command to get all kinds of details about an individual user based solely on the user's RID in decimal form (rpcclient annoyingly switches between hex RIDs and decimal RIDs in its output and between different commands). Remember how the original admin user on a Windows machine has a RID of 500, no matter the current user's name? Well, watch this:

rpcclient $> queryuser 500
User Name   :   Administrator
Full Name   :
Home Drive  :
Dir Drive   :
Profile Path:
Logon Script:
Description :   Built-in account for administering the computer/domain
Workstations:
Comment     :
Remote Dial :
Logon Time               :      Thu, 26 Jul 2012 03:22:17 EDT
Logoff Time              :      Wed, 31 Dec 1969 19:00:00 EST
Kickoff Time             :      Wed, 31 Dec 1969 19:00:00 EST
Password last set Time   :      Thu, 26 Jul 2012 03:27:04 EDT
Password can change Time :      Wed, 31 Dec 1969 19:00:00 EST
Password must change Time:      never
unknown_2[0..31]...
user_rid :      0x1f4
group_rid:      0x201
acb_info :      0x00000211
fields_present: 0x00ffffff
logon_divs:     168
bad_password_count:     0x00000000
logon_count:    0x00000001
padding1[0..7]...
logon_hrs[0..21]...

Note here that the output shows the last logon time for the user, as well as the Password last set Time. That kind of stuff is immensely valuable for auditors and penetration testers alike. And, the best part here is that you can get all of this information without an admin user name and password. With simply a non-admin account and SMB access, rpcclient can plunder all of this and much more from a target Windows machine. Note that the Dec 1969 dates are references to fields that are not set by Windows.

I'd like to encourage you to explore rpcclient further, checking out the multitude of additional commands and applying them in clever ways in your own penetration testing, vulnerability assessment, and audit work. If you come up with something cool, please let us know in the comments below.

Oh, and as a final note, if you are ever on a Windows machine and suspect that someone has established a nasty SMB session to you, you can get a list of all inbound SMB sessions into your machine by running the following command on Windows:

C:\> net session
Computer User name Client Type Opens  Idle time
-------------------------------------------------------
\10.10.75.2 TEST Unix        6   00:02:53

The command completed successfully.

Check out that Client Type: Unix. Nice. Our attacker is using Samba tools.

You can squash that SMB session coming into your Windows by running:

C:\> net session \[LinuxIPaddr] /del

You'll be prompted to verify you really want tear this session down. Hit y and it'll go away. Or, if you use a /y in the original command, it won't even prompt you before killing the session.

Now that I've killed that session, let's see what happens with good old Mr. rpcclient when I try to run an srvinfo again over on my Linux box:

rpcclient $> srvinfo
write_data: write failure. Error = Connection reset by peer
write_socket: Error writing 158 bytes to socket 3: ERRNO = Connection reset by peer
Error writing 158 bytes to client. -1 (Connection reset by peer)
rpc_api_pipe: Remote machine 10.10.76.1 pipe \srvsvc fnum 0x4001 returned critical error. Error was Write error: Connection reset by peer
result was DOS code 0x0000003b
rpcclient $>

Bah! Windows killed the SMB session, shutting rpcclient out.

Of course, the attacker can jump back in with rpcclient again. The defender can block that by configuring the built-in Windows firewall to block TCP port 445, but that would block any legit user's inbound SMB session. If you'd like to have a little more fun as a defender, you can play whack-a-mole with SMB sessions, using a Windows FOR loop to kill SMB sessions from your attacker every 1 second. That's sure to make the attacker scratch his head in annoyance:

C:\> FOR /L %i in (1,0,2) do @net session \[LinuxIPaddr] /del /y & ping -n 2 127.0.0.1>nul

Here, I'm running a FOR /L loop, which is a counter. It starts counting at 1, counts in steps of 0, up to 2. Thus, it'll keep running forever if we want it to. I declare a %i iterator variable that I don't ever use, but the syntax requires me to declare it. At each iteration of the loop, I drop the SMB session and then ping localhost twice, which introduces a 1-second delay. The first ping happens nearly instantly, the second one happens one second later. Our attacker will make a session, it'll last for a second, and then get blown up.

If you like this kind of topic, I'd encourage you to take a SANS Penetration Testing course, such as our SANS SEC504 course on Hacker Attacks, Exploits, and Incident Handling or our SANS SEC560 course on Network Penetration Testing and Ethical Hacking. You can take the courses anytime, online, OnDemand.

Thank you-

-Ed Skoudis

SANS Pen Test Curriculum Lead
Founder, Counter Hack
Director, SANS NetWars & CyberCity Projects

Share:
TwitterLinkedInFacebook
Copy url Url was copied to clipboard
Subscribe to SANS Newsletters
Join the SANS Community to receive the latest curated cybersecurity news, vulnerabilities, and mitigations, training opportunities, plus our webcast schedule.
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kingdom of Saudi Arabia
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia (Slovak Republic)
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
Zambia
Zimbabwe

Tags:
  • Penetration Testing and Ethical Hacking

Related Content

Blog
SUMMIT_Free_SANS_2021_Summits_Teaser.jpg
Digital Forensics and Incident Response, Cyber Defense Essentials, Industrial Control Systems Security, Purple Team, Blue Team Operations, Penetration Testing and Ethical Hacking, Cloud Security, Security Management, Legal, and Audit
November 30, 2020
Good News: SANS Virtual Summits Will Be FREE for the Community in 2021
They’re virtual. They’re global. They’re free.
Emily Blades
read more
Blog
Purple Team, Cyber Defense Essentials, Penetration Testing and Ethical Hacking
March 4, 2020
Instructor Spotlight: Stephen Sims, SEC599 Co-Author
Meet Stephen Sims. Stephen Sims is an industry expert with over 15 years of experience in information technology and security. Stephen currently works out of San Francisco as a consultant performing reverse engineering, exploit development, threat modeling, and penetration testing. Stephen has a...
Danyell Shin
read more
Blog
Penetration Testing and Ethical Hacking
March 24, 2013
Coinage: The SANS Pen Testing Coins Backstory
[Editor's Note: Some things I work on are the result of ten, thirty, or one-hundred minutes of effort. Others are the result of six months or a year of work (such as my office tour). This blog is the result of over a year's work by not only me, but also John Strand, Josh Wright, Kevin Johnson,...
370x370_Ed-Skoudis.jpg
Ed Skoudis
read more
  • Register to Learn
  • Courses
  • Certifications
  • Degree Programs
  • Cyber Ranges
  • Job Tools
  • Security Policy Project
  • Posters
  • The Critical Security Controls
  • Focus Areas
  • Blue Team Operations
  • Cloud Security
  • Cybersecurity Leadership
  • Digital Forensics
  • Industrial Control Systems
  • Offensive Operations
Subscribe to SANS Newsletters
Join the SANS Community to receive the latest curated cybersecurity news, vulnerabilities, and mitigations, training opportunities, plus our webcast schedule.
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kingdom of Saudi Arabia
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia (Slovak Republic)
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
Zambia
Zimbabwe
  • © 2021 SANS™ Institute
  • Privacy Policy
  • Contact
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn