Attacks
Exploiting MiTeC NetScanner: Tricky SEH exploit

VP of Hacking
Updated
Jul 9, 2020
15 min
In this article, we will create an exploit for MiTeC NetScanner 4.0.0.0, taking advantage of a vulnerability found some years ago.
The original report can be found here, and the author claims this at the end (sic):
In this post, we will try to overcome the aforementioned Exploit problems to see if we can come up with a working exploit with something like TCP
shell.
Vulnerability
The first thing to do is to identify the vulnerability. According to the author of the original exploit, it seems that there is a buffer overflow in the TOOLS → Detect IP from Host name…
functionality. Let’s check that:

Indeed. Now, we can start creating our proof-of-concept exploit:
From now on, we should open the resulting exploit.txt
file and copy/paste the resulting payload to NetScanner
. Do that under a debugger to check what’s going on:

Great. It seems to be an SEH overwrite vulnerability.
Now, we must check at what offset the SEH handler
is started to be overwritten. To do that, we can create a cyclic pattern using the Metasploit pattern_create.rb
tool:
Update our exploit with that:
And check it:

Now, check the offset with the pattern_offset.rb
tool:
Update our exploit with that offset:
And check it:

Great! Now, let’s check for bad chars.
Checking for bad chars
One of the problems mentioned by the original exploit author is that we must encode our shellcode using an alphanumeric encoder. We can verify the bad chars by sending an array with all the possible ASCII chars, excluding some usual suspects (carriage return \x0d
and line feed \x0a
). First, we must create the array on our debugger, so we can later compare it with our injected payload on memory. This can be done using this command:
And we can create the same string on our exploit:
Now, run the updated exploit to inject the resulting payload. We can compare the injected bytes with the in-memory bytes using:
In our case, that would be:
And the result is:
It seems that the only mangling occurred at the 00
byte that was modified to 20
. Also, it seems that the buffer was dropped after AC
. We can inject the other part of the ASCII array to check that:
The result is:

And the comparison table result is:

Well, it seems that after all, only the 0x00
, 0x0a
and 0x0d
chars are not allowed. Not bad.
Exploiting
Now that we know the nature of the vulnerability, we can start the actual exploitation. The first thing to do is check if NetScanner
has executable modules without SafeSEH
enabled. To do that, we can use the following mona
command:
And the result is:

It seems that the only module compiled without SafeSEH
is the executable itself. However, as you can see in the Base
address, it starts with 00
, which means that when we inject it, it would be translated to 20
, according to the bad chars analysis we just did. Let’s check that anyway.
First, let’s find suitable POP/POP/RET
sequences with:

At least we have a lot. I’ll pick the first one at 00407119
:

Update our exploit with that:
And check it:

Look carefully at the resulting stack state:

Several things are important to notice:
The
00
byte on ourPOP/POP/RET
sequence was mangled and changed to20
, as expected.The application somehow overwrites part of the
A
chars with0
atnSEH-8
.The
C
buffer seems unaffected.
Now check the end of the C
buffer:

We can see that there are some 00
bytes here, probably left-overs of the affected function stack frame. We can leverage those 00
to get our desired POP/POP/RET
address.
3-byte overwrite
To overcome the problem of the NULL byte mangling, we can do a partial overwrite of the SEH
handler. What we first did was:
And that’s where our \x00
byte was changed to 0x20
. Let’s check what would happen if we write only 3 bytes of the POP/POP/RET
address, like this:
Update our exploit:
And check it:

Awesome! We used the stack left-overs to complete our POP/POP/RET
address.
Now, if we run the POP/POP/RET
sequence, we would land at nSEH
which is only 4 bytes:

And as we don’t have any bytes after the SEH
handler, we must jump back to the start of our A
buffer. With the help of our debugger, we can get the needed bytes EB B4
. We can update our nSEH
with that:
And check it:

Great! We now have 61 bytes to work.
Alternate ending: Egghunter
With 61 bytes, we have some room to work. The first thing that comes to mind is the use of an egghunter. Let’s do that.
We first must create the egghunter. I will use the egg osce
this time:
Update our exploit with that:
And check it:

Great. The egghunter is now ready, but there is nothing to hunt. We must create a shellcode, place it anywhere on memory and prepend it with our osceosce
egg. But where?
After some analysis of NetScanner
, I discovered a functionality called Remote Execute…
on where several parameters are needed, but there is one called Command line
that accepts long alphanumeric strings. To our favor, when we type something, it stays on memory:

Let’s check if we can use that field to insert our shellcode. First, we must create an alphanumeric shellcode:
Notice that I used the BufferRegister=EDI
parameter because EDI
is the register on where our egghunter will point the start of the shellcode. Let’s update our exploit with that:
Note that I included some instructions. Also, I included osceosce
at the start of the shellcode. Let’s check it:

Awesome!
We were able to overcome all the original exploit problems.
You can download the final exploit here.
Conclusion
Sometimes, we need to be creative when creating our exploits. In this article, we were able to leverage stack left-overs and other functionalities of the vulnerable application to get a fully working exploit.
Get started with Fluid Attacks' PTaaS right now
Other posts