Skip to content

Instantly share code, notes, and snippets.

@secdev02
Last active December 9, 2025 17:15
Show Gist options
  • Select an option

  • Save secdev02/4d2e1c18c019cfba26aaefa660d1e738 to your computer and use it in GitHub Desktop.

Select an option

Save secdev02/4d2e1c18c019cfba26aaefa660d1e738 to your computer and use it in GitHub Desktop.
OMGData - Using Odata for C2 basic construct.

Create an Odata listener,

Then se how to fetch it with DataSVCUtil

Run you listener

Fetch

C:\Windows\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /uri:http://localhost:8080/odata /out:HelloODataClient.cs /Version:1.0

# HelloOData.ps1 - Minimal OData Service
$url = "http://localhost:8080/"
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add($url)
$listener.Start()
Write-Host "OData service running at $url"
Write-Host "Try: ${url}odata/`$metadata"
Write-Host "Try: ${url}odata/Messages"
Write-Host "Press Ctrl+C to stop"
try {
while ($listener.IsListening) {
$context = $listener.GetContext()
$request = $context.Request
$response = $context.Response
$path = $request.Url.AbsolutePath
Write-Host "Request: $path"
if ($path -eq "/odata/`$metadata") {
# OData Metadata
$metadata = @"
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="2.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="HelloOData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Message">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="Text" Type="Edm.String" />
<Property Name="Timestamp" Type="Edm.DateTime" />
</EntityType>
<EntityContainer Name="HelloODataContext" m:IsDefaultEntityContainer="true">
<EntitySet Name="Messages" EntityType="HelloOData.Message" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
"@
$buffer = [System.Text.Encoding]::UTF8.GetBytes($metadata)
$response.ContentType = "application/xml"
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
}
elseif ($path -eq "/odata/Messages") {
# Sample data
$data = @"
{
"value": [
{
"Id": 1,
"Text": "Hello from OData!",
"Timestamp": "2024-12-09T10:00:00Z"
},
{
"Id": 2,
"Text": "Build system test",
"Timestamp": "2024-12-09T11:00:00Z"
}
]
}
"@
$buffer = [System.Text.Encoding]::UTF8.GetBytes($data)
$response.ContentType = "application/json"
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
}
else {
# 404
$response.StatusCode = 404
$buffer = [System.Text.Encoding]::UTF8.GetBytes("Not Found")
$response.OutputStream.Write($buffer, 0, $buffer.Length)
}
$response.Close()
}
}
finally {
$listener.Stop()
Write-Host "`nService stopped"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment