Raikia / SMBCrunch

3 tools that work together to simplify reconaissance of Windows File Shares
GNU General Public License v3.0
161 stars 26 forks source link

Unfiltered Network Share Names Allows Arbitrary Command Execution & Arbitrary File Write #3

Closed 0xchrisb closed 6 years ago

0xchrisb commented 6 years ago

There is a vulnerability in SMBList.pl which allows an attacker (e.g. server administrator) to execute arbitrary commands on the system on which the script was executed.

Attack path 1:

  1. Create a share which contains ' in the name in order to break out of the string in SMBList.pl line 121

my $smbclient_cmd = `timeout $inputMaxExec smbclient -N -A '$tempAuthFile' '$share' -c 'recurse;dir' 2>&1 > temporary_running_file.txt`;

**Samba config:**
[Data' -c 'exit';touch /tmp/oops;echo 'oops]
  comment = My Partition
  create mask = 0775
  directory mask = 0775
  browseable = yes
  path = /asd asd
  guest ok = yes
  available = yes
  public = yes
  writable = yes
  1. Run SMBHunt.pl and something like the following will be returned: \\172.11.132.1\Data' -c 'exit';touch /tmp/oops;echo 'oops

  2. Run SMBList.pl, a file (/tmp/oops) is now created. This can of course be changed to any command.

Fix: escape $share, such as via: $share =~ s/'/'\''/g;

Attack path 2: After indexing a fileshare, the name of the fileshare is used within perl's open() function. This may lead to an issue if

Fix: replace / with -

Raikia commented 6 years ago

Excellent, thanks for the fixes. This is an example of a personal script I wrote where I personally judge the inputs to check for unsafe values before running it. Good fixes and I appreciate the merge request!