Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing a Sortable Task Queue for Scanning Operations

Tech 1

To prevent loss of plugin data during Goby's plugin reloads, a data.json file is created within the plugin's directory to persistently store task information.

fs.writeFile(this.filePath, JSON.stringify({"data": []}, null, 6), (err) => {});

Retrieving Scan Configuration Data

For users to define custom scan tasks, essential scanning parameters such as port lists, vulnerability checks (POCs), and scan order options must be retrieved using dedicated APIs: getPortList, getVulnerabilityList, and getOrderList.

goby.getPortList().then((res) => {
    config.port = res.data;
    let options = '';
    res.data.forEach(item => {
        options += `<option value="${item.type}">${item.type}</option>`;
    });
    $('.port').html(options);
    form.render('select');
    $('.portcontent').val(res.data[0].value);
});

goby.getVulnerabilityList().then((res) => {
    let options = '';
    res.data.forEach(vuln => {
        options += `<option value="${vuln}">${vuln}</option>`;
    });
    $('.vulnerability').html(options);
    form.render('select');
});

goby.getOrderList().then((res) => {
    let options = '';
    res.data.forEach(order => {
        options += `<option value="${order}">${order}</option>`;
    });
    $('.order').html(options);
    form.render('select');
});

Event Binding for Task Lifecycle Menagement

To manage the task queue dynamically, events such as scan start, pause, and completion must trigger appropriate actions like launching the next queued task or refreshing the UI. The following snippet demonstrates refreshing the queue UI after a scan is paused, with a one-second delay to allow for file system updates.

goby.bindEvent('onPauseScan', () => {
    setTimeout(() => {
        init();
    }, 1000);
});

Initiating a Scan Task

When starting a scan, the selected task configuration is passed to startScan. Upon success, the task ID is recorded and the queue state is updated in the presistent JSON file.

goby.startScan(queue.data[index]).then((res) => {
    queue.data[index].taskId = res.data.taskId;
    queue.data[index].state = 1;
    fs.writeFile(this.filePath, JSON.stringify(queue, null, 6), (err) => {
        if (err) {
            reject(err);
        } else {
            resolve(res);
        }
    });
});

Managing the Task Queue in a Shared Context

To enable interaction with the task queue from custom modal windows, a global taskQueue instance is initialized in extension.js.

window.taskQueue = new TaskQueue();

This instance exposes methods such as adding, removing, and starting tasks. From a modal window, the parent context provides access to both the Goby API and the shared queue.

const goby = parent.goby;
const taskQueue = parent.taskQueue;

Queue operations can then be performed directly. For example, removing a task on user request:

$('.con').delegate('.delete', 'click', function() {
    const queueId = $(this).parent().attr('queueId');
    taskQueue.delete([queueId]).then(() => {
        init();
    });
});

Future enhancements to this plugin include scheduled scans and drag-and-drop reordering of tasks, enabling automated and user-friendly scan menagement.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.