Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
v0.1.0 BETA. Introducing big files (more than 2 kbs), ability to add …
Browse files Browse the repository at this point in the history
…contents of files externally, fixing JSON format, adding CHANGELOG for every commit since v0.1.0 BETA.
  • Loading branch information
kolya5544 committed Jan 27, 2020
1 parent 3884228 commit 171e8ff
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 48 deletions.
30 changes: 15 additions & 15 deletions BearFTP/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class Config
public string Banner = "Welcome to FTP!";

public List<CJSON_FILE> files;

static string PlaceHolder = @"{
'PortDef': 21,
'PortPasv': 21,
'Hostname': '127.0.0.1',
'Token': '',
'Report': true,
'Ban': true,
'PunishScans': true,
'Files': [{
'Name': 'readme.txt',
'Content': 'Please, dont insert content which is more than 2048 bytes!'
}],
'Banner': 'Welcome to FTP!'
}";
static string PlaceHolder = "{\r\n"+
"\"PortDef\": 21,\r\n"+
"\"PortPasv\": 21,\r\n"+
"\"Hostname\": \"127.0.0.1\",\r\n" +
"\"Token\": \"\",\r\n" +
"\"Report\": true,\r\n" +
"\"Ban\": true,\r\n" +
"\"PunishScans\": true,\r\n" +
"\"Files\": [{\r\n" +
" \"Name\": \"readme.txt\",\r\n" +
" \"Content\": \"Please, dont insert content which is more than 2048 bytes!\"\r\n" +
"}],\r\n" +
"\"Banner\": \"Welcome to FTP!\"\r\n" +
"}";

public Config(string name)
{
Expand Down
74 changes: 66 additions & 8 deletions BearFTP/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Sockets;
using System.Threading;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -42,7 +42,7 @@ class Program
public static Directory root = new Directory();

//Current version
public static string _VERSION = "v0.0.2 BETA";
public static string _VERSION = "v0.1.0 BETA";

//Default log.
public static StreamWriter logfile = new StreamWriter("log.txt", true);
Expand Down Expand Up @@ -232,6 +232,8 @@ public static void Log(string text, string dir, bool date = true, string IP = nu

Builder += text;

Builder = Regex.Replace(Builder, @"[^\u0000-\u007F]+", " ");

logfile.WriteLine(Builder);
Console.WriteLine(Builder);
}
Expand Down Expand Up @@ -259,7 +261,7 @@ static void Main(string[] args)
}

//Yes, it starts..
Console.WriteLine("- FTP OpenSource HoneyPot Server " + _VERSION + " -");
Console.WriteLine("- BearFTP OpenSource HoneyPot Server " + _VERSION + " -");
Console.WriteLine("- By IKTeam -> https://github.com/kolya5544/BearFTP -");
Console.WriteLine("Checking for updates...");
if (!CheckVersion())
Expand Down Expand Up @@ -546,9 +548,11 @@ static void Main(string[] args)
Thread.Sleep(1000);
LogWrite("150 Ok to send data.\r\n", sw, hostname);
Thread.Sleep(100);
byte[] file = aaaa.content;
char[] chars = Encoding.ASCII.GetChars(file);
connn.sw.Write(chars, 0, file.Length);
// byte[] file = aaaa.content;
//Encoding.ASCII.GetChars(file);
// connn.sw.Write(chars, 0, file.Length);
// connn.tcp.Close();
SendFile(aaaa, connn.sw);
connn.tcp.Close();
Thread.Sleep(200);
LogWrite("226 Transfer complete!\r\n", sw, hostname);
Expand Down Expand Up @@ -798,14 +802,68 @@ private static void InitializeFiles()
{
foreach (CJSON_FILE json in config.files)
{
File file = new File(json.Name, json.Content.Length, "-rw-r--r--", "Dec 1 15:11", json.Content, root);
files.Add(file);
if (!json.Content.StartsWith("---"))
{
File file = new File(json.Name, json.Content.Length, "-rw-r--r--", "Dec 1 15:11", json.Content, root);
files.Add(file);
} else
{
try
{
var filecontents = System.IO.File.ReadAllBytes(json.Content.Substring(3, json.Content.Length - 3));
File file = new File(json.Name, filecontents.Length, "-rw-r--r--", "Dec 1 15:11", filecontents, root);
files.Add(file);
} catch (Exception e)
{
Console.WriteLine(e.Message);
}

}
}
} else
{
File file = new File("readme.txt", 3, "-rw-r--r--", "Dec 1 15:10", "Hi!", root);
files.Add(file);
}

}

/// <summary>
/// Sends contents of files in 2 kilobyte packs
/// </summary>
/// <param name="file">File to send</param>
/// <param name="sw">Actual StreamWriter of PASV mode</param>
public static void SendFile(File file, StreamWriter sw)
{
if (file.size <= 2048)
{
sw.BaseStream.Write(file.content, 0, file.size);
} else
{
//Ok boomer
//1. We calculate amount of steps (a.k.a how much should we do the loop)
//2. We calculate offtop based on steps we already passed
//3. We take 2048 bytes since that offtop and send them......
//it's hard but here's the actual code:

int Steps = 0;
int Offtop = 0;
int Leftover = 0;

byte[] buffer = new byte[2048];
Steps = Math.DivRem(file.size, 2048, out Leftover);
for(Offtop = 0; Offtop<Steps; Offtop++)
{
Array.Copy(file.content, Offtop * 2048, buffer, 0, 2048);
sw.BaseStream.Write(buffer, 0, buffer.Length);
Thread.Sleep(50); //Trying to limit possible attacks.
}
var last = new byte[file.size - Offtop *2048];
Array.Copy(file.content, file.size - Leftover, last, 0, Leftover);
sw.BaseStream.Write(last, 0, last.Length);
Thread.Sleep(50);
return;
}
}
}
}
26 changes: 13 additions & 13 deletions BearFTP/example_config/config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
'PortDef': 21,
'PortPasv': 1222,
'Hostname': '145.239.82.241',
'Token': '',
'Report': true,
'Ban': true,
'PunishScans': true,
'Files': [
"PortDef": 21,
"PortPasv": 1222,
"Hostname": "145.239.82.241",
"Token": "",
"Report": true,
"Ban": true,
"PunishScans": true,
"Files": [
{
'Name': 'sqlite.db',
'Content': 'You are not allowed to see the contents of this file!'
"Name": "sqlite.db",
"Content": "You are not allowed to see the contents of this file!"
},
{
'Name': 'parsed1.db',
'Content': 'You are not allowed to see the contents of this file!'
"Name": "parsed1.db",
"Content": "You are not allowed to see the contents of this file!"
}],
'Banner': 'ProFTPd 1.3.5 Server [%host]'
"Banner": "ProFTPd 1.3.5 Server [%host%]"
}
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--> IT ONLY CONTAINS THE MOST RECENT CHANGES!

v0.1.0:
- Ability to RECV files more than 2 kbs in size
- Ability to add byte[] contents to files (a.k.a you can now send .exes over FTP)
- JSON format fixed
- Possible fix of unique characters breaking encoding of logs.
- Download speed limited to 40 kbit/sec.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ $ dotnet BearFTP.dll
The program should exit with an error. Proceed to editing the **config.json**
```json
{
'PortDef': 21,
'PortPasv': 21,
'Hostname': '127.0.0.1',
'Token': '',
'Report': true,
'Ban': true,
'PunishScans': true,
'Files': [{
'Name': 'readme.txt',
'Content': 'Please, dont insert content which is more than 2048 bytes!'
"PortDef": 21,
"PortPasv": 21,
"Hostname": "127.0.0.1",
"Token": "",
"Report": true,
"Ban": true,
"PunishScans": true,
"Files": [{
"Name": "readme.txt",
"Content": "Please, dont insert content which is more than 2048 bytes!"
}],
'Banner': 'Welcome to FTP!'
"Banner": "Welcome to FTP!"
}
```
| Key | Value |
Expand All @@ -67,10 +67,11 @@ The program should exit with an error. Proceed to editing the **config.json**
| PunishScans | Should we ban/report nmap scanners? |
| Files[] | Array of files. |
| Files[Name] | Filename |
| Files[Content] | Contents of files (string). No more than 2 kbs. |
| Files[Content] | Contents of files (string). Start with --- to make it load from a file (example: "---file.exe") |
| Banner | Banner sent right after TCP handshake. %host% will be replaced with current hostname |

To make it work, you should change PortPasv to any other value, so PortPasv is not equal to PortDef. Other options are optional.
**We highly dont recommend using files with size of more than 4 MB! You should not use honeypot as a real FTP server to share files!**

### Development

Expand Down

0 comments on commit 171e8ff

Please sign in to comment.