Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DownloadFile() not working with bofnet_job #2

Open
williamknows opened this issue Jul 18, 2021 · 1 comment
Open

DownloadFile() not working with bofnet_job #2

williamknows opened this issue Jul 18, 2021 · 1 comment

Comments

@williamknows
Copy link

williamknows commented Jul 18, 2021

Hey,

Really appreciate the effort that's gone into supporting the undocumented BOF functionality.

I've run into an issue with DownloadFile(). It appears to work fine with bofnet_execute but throws a NullReferenceException error with bofnet_job. This may be down to the way I'm using it. If so, would appreciate some code samples on usage if you have the time.

Test Code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BOFNET;

namespace BOFNET_TestFileDownload
{
    class Program : BeaconObject
    {
        public Program(BeaconApi api) : base(api) { }
        public override void Go(string[] args)
        {
            MemoryStream ms = new MemoryStream();
            using (FileStream file = new FileStream(@"C:\temp\Testing.txt", FileMode.Open, FileAccess.Read))
                file.CopyTo(ms);
            ms.Position = 0;
            DownloadFile("testfile.txt", ms);
            ms.Close();

            BeaconConsole.WriteLine($"[+] File sent!");
        }

        static void Main(string[] args)
        {
        }
    }
}

Output

beacon> bofnet_execute BOFNET_TestFileDownload.Program
[*] Attempting to execute BOFNET BOFNET_TestFileDownload.Program
[+] host called home, sent: 6809 bytes
[*] started download of testfile.txt (24 bytes)
[*] download of testfile.txt is complete
[+] received output:
[+] File sent!

beacon> bofnet_job BOFNET_TestFileDownload.Program
[*] Attempting to start BOFNET BOFNET_TestFileDownload.Program as a job
[+] host called home, sent: 6836 bytes
[+] received output:
[+] Started Task BOFNET_TestFileDownload.Program with job id 4

beacon> bofnet_jobstatus 4
[*] Attempting to execute BOFNET BOFNET.Bofs.Jobs.JobStatus
[+] host called home, sent: 6808 bytes
[+] received output:
Type: Program, Id: 4, Active: False, Console Data: True
Job execution failed with exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at BOFNET.BeaconObject.DownloadFile(String fileName, Stream fileData)
   at BOFNET_TestFileDownload.Program.Go(String[] args)
   at BOFNET.BeaconJob.DoTask(Object args)

[+] Job completed and console drained, removing from active job list
@CCob
Copy link
Owner

CCob commented Jul 18, 2021

Unfortunately it won't work as a job. The native BOF runtime is long gone when you start a job so you can't use any of the BOF APIs. It works for console output because it's cached and is only spewed out during a call to bofnet_jobstatus. I should put guard rails in place to prevent these undocumented extensions from working in a job.

@CCob CCob closed this as completed Aug 22, 2021
CCob added a commit that referenced this issue Nov 13, 2023
…eaconGetValue pairs

This commit also fixes issue #2 and #3
CCob added a commit that referenced this issue Nov 13, 2023
@CCob CCob reopened this Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants