-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
757 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.vs | ||
*.user | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
[Bb]in/ | ||
[Oo]bj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# SharpPrinter | ||
|
||
Printer is a modified and console version of [ListNetworks](https://github.com/vinifr/-ListNetworks) | ||
|
||
As an example, one could execute SharpPrinter.exe through Cobalt Strike's Beacon "execute-assembly" module. | ||
|
||
|
||
#### Example usage | ||
beacon>execute-assembly /root/SharpPrinter/SharpPrinter.exe | ||
|
||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.136 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpPrinter", "SharpPrinter\SharpPrinter.csproj", "{41B2D1E5-4C5D-444C-AA47-629955401ED9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{41B2D1E5-4C5D-444C-AA47-629955401ED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{41B2D1E5-4C5D-444C-AA47-629955401ED9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{41B2D1E5-4C5D-444C-AA47-629955401ED9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{41B2D1E5-4C5D-444C-AA47-629955401ED9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7402AD4A-5A96-4C65-8A1F-D85F8AE0E10B} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<Costura /> | ||
</Weavers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> | ||
<xs:element name="Weavers"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element name="Costura" minOccurs="0" maxOccurs="1"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="DisableCompression" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="DisableCleanup" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="LoadAtModuleInit" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="ExcludeAssemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="IncludeAssemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="Unmanaged32Assemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="Unmanaged64Assemblies" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="PreloadOrder" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="GenerateXsd" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Net.NetworkInformation; | ||
using SnmpSharpNet; | ||
|
||
namespace SharpPrinter | ||
{ | ||
|
||
class Program | ||
{ | ||
public class Printers | ||
{ | ||
public static List<string> PrinterList = new List<string>(); | ||
} | ||
|
||
static string GetLocalIPv4(NetworkInterfaceType _type) | ||
{ | ||
string output = null; | ||
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) | ||
{ | ||
if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up) | ||
{ | ||
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses) | ||
{ | ||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork) | ||
{ | ||
output = ip.Address.ToString(); | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
} | ||
|
||
static bool getSnmpnext(string host, string OID) | ||
{ | ||
bool result = false; | ||
|
||
SimpleSnmp snmpVerb = new SimpleSnmp(host, 161, "public", 500, 0); | ||
if (!snmpVerb.Valid) | ||
{ | ||
return result; | ||
} | ||
Oid varbind = new Oid(OID); | ||
Dictionary<Oid, AsnType> snmpDataS = snmpVerb.GetNext(SnmpVersion.Ver1, new string[] { varbind.ToString() }); | ||
if (snmpDataS != null) | ||
{ | ||
result = true; | ||
} | ||
return result; | ||
} | ||
|
||
static bool getSnmp(string host, string OID) | ||
{ | ||
bool result = false; | ||
|
||
SimpleSnmp snmpVerb = new SimpleSnmp(host, 161, "public", 500, 0); | ||
if (!snmpVerb.Valid) | ||
{ | ||
return result; | ||
} | ||
|
||
Oid varbind = new Oid(OID); | ||
|
||
Dictionary<Oid, AsnType> snmpDataS = snmpVerb.Get(SnmpVersion.Ver1, new string[] { varbind.ToString() }); | ||
if (snmpDataS != null) | ||
{ | ||
string temp = snmpDataS[varbind].ToString(); | ||
// Get MANUFACTURER | ||
int startIndex = temp.IndexOf("MFG:"); | ||
int endIndex = temp.IndexOf(";", startIndex); | ||
string mfg = temp.Substring(startIndex + 4, endIndex - (startIndex + 4)); | ||
// Get MODEL | ||
startIndex = temp.IndexOf("MDL:"); | ||
endIndex = temp.IndexOf(";", startIndex); | ||
string printerMDL = temp.Substring(startIndex + 4, endIndex - (startIndex + 4)); | ||
Printers data = new Printers(); | ||
Printers.PrinterList.Add(host + " " + mfg + " " + printerMDL); | ||
|
||
} | ||
else if (snmpDataS == null) | ||
{ | ||
Console.WriteLine("No Printers Found."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Not Response from " + host); | ||
} | ||
|
||
|
||
return result; | ||
} | ||
|
||
|
||
[DllImport("iphlpapi.dll", ExactSpelling = true)] | ||
public static extern int SendARP(int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen); | ||
|
||
static void SendArpRequest(IPAddress dst) | ||
{ | ||
byte[] macAddr = new byte[6]; | ||
uint macAddrLen = (uint)macAddr.Length; | ||
int uintAddress = BitConverter.ToInt32(dst.GetAddressBytes(), 0); | ||
|
||
if (SendARP(uintAddress, 0, macAddr, ref macAddrLen) == 0) | ||
{ | ||
getSnmpnext(dst.ToString(), "1.3.6.1.2.1.43"); | ||
if (getSnmpnext(dst.ToString(), "1.3.6.1.2.1.43") == true) | ||
{ | ||
/* PRINTER-PORT-MONITOR-MIB - 1.3.6.1.4.1.2699 | ||
* ppmPrinterIEEE1284DeviceId: 1.3.6.1.4.1.2699.1.2.1.2.1.1.3 | ||
* ppmPrinterName: 1.3.6.1.4.1.2699.1.2.1.2.1.1.2 | ||
*/ | ||
getSnmp(dst.ToString(), "1.3.6.1.4.1.2699.1.2.1.2.1.1.3.1"); | ||
} | ||
} | ||
} | ||
|
||
static void ScanPrinters() | ||
{ | ||
string prefix = null; | ||
|
||
string temp = GetLocalIPv4(NetworkInterfaceType.Ethernet); | ||
if (temp != null) | ||
prefix = temp.Substring(0, 3); | ||
if (temp == null || (prefix == "169")) | ||
temp = GetLocalIPv4(NetworkInterfaceType.Wireless80211); | ||
string ipBase = temp; | ||
try | ||
{ | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
ipBase = temp.Remove(ipBase.Length - 1); | ||
if (ipBase.EndsWith(".")) | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("Errormessage = " + ex.Message); | ||
} | ||
|
||
//Generating IP Range | ||
List<IPAddress> ipAddressList = new List<IPAddress>(); | ||
for (int i = 1; i < 254; i++) | ||
{ | ||
//Obviously you'll want to safely parse user input to catch exceptions. | ||
ipAddressList.Add(IPAddress.Parse(ipBase + i)); | ||
} | ||
|
||
foreach (IPAddress ip in ipAddressList) | ||
{ | ||
Thread thread = new Thread(() => SendArpRequest(ip)); | ||
thread.Start(); | ||
} | ||
|
||
} | ||
static void Main(string[] args) | ||
{ | ||
try | ||
{ | ||
|
||
Task task = Task.Run(() => ScanPrinters()); | ||
task.Wait(); | ||
Thread.Sleep(2000); | ||
Printers data = new Printers(); | ||
Printers.PrinterList.ForEach(i => Console.WriteLine("{0}\t", i)); | ||
Console.WriteLine(""); | ||
Console.WriteLine("Done!"); | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SharpPrinter")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SharpPrinter")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("41b2d1e5-4c5d-444c-aa47-629955401ed9")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.