-
Notifications
You must be signed in to change notification settings - Fork 4
/
NFS.cs
121 lines (115 loc) · 5.94 KB
/
NFS.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
namespace Reecon
{
class NFS // Port 2049
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Port is always required")]
public static (string, string) GetInfo(string target, int port)
{
// TODO: https://svn.nmap.org/nmap/scripts/nfs-ls.nse
string fileList = "";
if (General.GetOS() == General.OS.Windows)
{
if (File.Exists(@"C:\Windows\System32\showmount.exe"))
{
List<string> outputLines = General.GetProcessOutput(@"C:\Windows\System32\showmount.exe", "-e " + target);
if (outputLines.Count > 1)
{
outputLines.RemoveAt(0);
fileList = "- Files:" + Environment.NewLine;
foreach (string line in outputLines)
{
fileList += "-- " + line + Environment.NewLine;
}
fileList = fileList.Trim(Environment.NewLine.ToCharArray());
fileList += Environment.NewLine + $"- To Mount --> mount \\\\{target}\\shareNameHere x:";
}
fileList = fileList.Trim(Environment.NewLine.ToCharArray());
return ("NFS", fileList);
}
else
{
fileList = "- showmount does not exist - Bug Reelix to update this section for more compatibility";
return ("NFS", fileList);
}
}
else if (General.GetOS() == General.OS.Linux)
{
if (General.IsInstalledOnLinux("showmount")) // "/sbin/showmount" OR "/usr/sbin/showmount"
{
List<string> showmountOutput = General.GetProcessOutput("showmount", "-e " + target);
foreach (string line in showmountOutput)
{
// A portable version of bash
// https://github.com/TheRealPoloMints/Blog/blob/master/Security%20Challenge%20Walkthroughs/Networks%202/bash
// NFS V1
if (line.Trim().EndsWith("*"))
{
fileList += "- " + line.Recolor(Color.Orange) + Environment.NewLine;
fileList += "-- NFSV1 -> " + $"sudo mount -t nfs {target}:/mountNameHere /tmp/mount/ -nolock".Recolor(Color.Orange) + Environment.NewLine;
fileList += "--- " + "Try copy over a version of bash onto the share, +s +x it, then ./bash -p".Recolor(Color.Orange) + Environment.NewLine;
}
// NFS V2
else if (line.Contains(" (everyone)"))
{
fileList += "- " + line.Recolor(Color.Orange) + Environment.NewLine;
fileList += "-- NFSV2 -> " + $"sudo mount -t nfs -o vers=2 {target}:/mountNameHere /mnt".Recolor(Color.Orange) + Environment.NewLine;
fileList += "--- " + "Try copy over a version of bash onto the share, +s +x it, then ./bash -p".Recolor(Color.Orange) + Environment.NewLine;
}
// This took me far too long to figure out
else if (line.Contains("clnt_create: RPC: Program not registered"))
{
fileList = "- showmount cannot connect to the NFS service on port 2049 :(" + Environment.NewLine;
}
else
{
fileList += "- " + line + Environment.NewLine;
}
}
fileList = fileList.Trim(Environment.NewLine.ToCharArray());
return ("NFS", fileList);
//
// Windows
//
// ManagementClass objMC = new ManagementClass("Win32_ServerFeature"); // Only in Windows Server 2008 / R2
/*
ManagementClass objMC = new ManagementClass("Win32_OptionalFeature");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
//Console.WriteLine("Woof!");
string featureName = (string)objMO.Properties["Name"].Value;
if (!featureName.ToUpper().Contains("NFS"))
{
continue;
}
uint installState = 0;
try
{
installState = (uint)objMO.Properties["InstallState"].Value; // 1 = Enabled, 2 = Disabled, 3 = Absent, 4 = Unknown
}
catch
{
Console.WriteLine("Error - InstallState is: " + (string)objMO.Properties["InstallState"].Value);
}
//add to my list
Console.WriteLine("Installed: " + featureName + " -> " + installState);
}
*/
}
else
{
return ("NFS", "- Error - showmount is not installed - Unable to enumerate! Run: sudo apt install nfs-common".Recolor(Color.Red));
}
}
else
{
Console.WriteLine("Error - OS Not Supportd - Bug Reelix");
}
return ("NFS?", "- Bug Reelix");
}
}
}