• How to fix Ctrl-Tab behavior in Kate?

    Kate has tabs turned off by default (at least that’s what you get with vanilla Kate package from Arch Linux repositories) and even when you turn them on, they act kinda funky because Kate switches between tabs by name order, rather than by opening order so what happens is that Ctrl-Tab starts jumping between your tabs instead of going from one to another, from left to right. That was quite confusing to me, and I wanted to change that behavior to what I’m already used to in browsers, GEdit, Pidgin, whatever… Finding a solution (a very well camouflaged one for that matter, thank you) to this situation was rather… unexpected.

    To turn tabs on (if they’re not turned on by default in your distro) you will first have to go to Settings -> Configure Kate -> Plugins and turn on either “Tab Bar” or “Multiline Tab Bar”. Try both and then decide which one suits you better. After that you will have to set up the shortcut for switching between tabs. To do that, go to Settings -> Configure Shortcuts and set the shortcut for Forward to Ctrl-Tab. You could as well set up alternate shortcuts: Alt+1 for Back and Alt+2 for Forward. You will be able to toggle tabs in both directions then easily.

    To fix the tab switching behavior (ordering), open the Documents column from the File System Browser (if you have it turned off, turn it on under plugins), right-click on it and choose Opening Order from Sort By in the drop-down menu.

    That’s it, enjoy!

  • Automating Risu report dumping

    Here is a small bash script to automate Risu reporting. It’s not the most elegant thing out there, but it gets the job done. You will have to make Risu config file beforehand and put it in the same folder with this script and all the Nessus scans you’ve got. The script will pipe all the scans into Risu, create pdf reports for you and dump them into the same folder.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    #!/bin/bash
    # perhaps you will have to set custom Risu path
    #risu="/var/lib/gems/1.9.1/bin/risu"
    nessus_logs=()

    $risu --create-tables

    for file in $(ls *.nessus);
    do
       nessus_logs=("${nessus_logs[@]}" $file)
    done

    $risu ${nessus_logs[@]}
    echo -e "\n"

    echo "Dumping findings_summary.pdf"
    $risu -t findings_summary -o "findings_summary.pdf"

    echo "Dumping findings_summary_with_pluginid.pdf"
    $risu -t findings_summary_with_pluginid -o "findings_summary_with_pluginid.pdf"

    echo "Dumping exec_summary.pdf"
    $risu -t exec_summary -o "exec_summary.pdf"

    echo "Dumping cover_sheet.pdf"
    $risu -t cover_sheet -o "cover_sheet.pdf"

    echo "Dumping pci_compliance.pdf"
    $risu -t pci_compliance -o "pci_compliance.pdf"

    echo "Dumping ms_update_summary.pdf"
    $risu -t ms_update_summary -o "ms_update_summary.pdf"

    echo "Dumping graphs.pdf"
    $risu -t graphs -o "graphs.pdf"

    echo "Dumping technical_findings.pdf"
    $risu -t technical_findings -o "technical_findings.pdf"

    echo "Dumping finding_statistics.pdf"
    $risu -t finding_statistics -o "finding_statistics.pdf"

    echo "Dumping assets.pdf"
    $risu -t assets -o "assets.pdf"

    echo "Dumping exec_summary_detailed.pdf"
    $risu -t exec_summary_detailed -o "exec_summary_detailed.pdf"

    echo "Dumping host_summary.pdf"
    $risu -t host_summary -o "host_summary.pdf"

    echo "Dumping findings_host.pdf"
    $risu -t findings_host -o "findings_host.pdf"

    echo "Dumping ms_patch_summary.pdf"
    $risu -t ms_patch_summary -o "ms_patch_summary.pdf"

    echo "Dumping template.pdf"
    $risu -t template -o "template.pdf"

    echo -e "\n"
    $risu --drop-tables
  • How to generate an IP range list in Python?

    How to generate an IP range list in Python?

    Here’s a short Python snippet that generates a list of IP addresses based on IP range. Nothing fancy, but could come in handy if you ever need it somewhere in your code. Enjoy!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    def ipRange(start_ip, end_ip):
       start = list(map(int, start_ip.split(".")))
       end = list(map(int, end_ip.split(".")))
       temp = start
       ip_range = []
       
       ip_range.append(start_ip)
       while temp != end:
          start[3] += 1
          for i in (3, 2, 1):
             if temp[i] == 256:
                temp[i] = 0
                temp[i-1] += 1
          ip_range.append(".".join(map(str, temp)))    
         
       return ip_range
       
       
    # sample usage
    ip_range = ipRange("192.168.1.0", "192.171.3.25")
    for ip in ip_range:
       print(ip)
  • Merging multiple Nessus scans (Python script)

    nessus

    If you for any reason have the need to merge / combine a few Nessus scans into a single *.nessus file, you can do so using this simple Python script. Since *.nessus files are basically just XML files with a different extension, what this script does is it finds all the *.nessus files in the current folder, finds all the “ReportHost” XML nodes accumulating them into a single report.nessus file which is then exported to nss_report folder.

    Note that scans must be of the same type (same plugins must be used), but they can be from different subnets or different parts of the same subnet.

    How to use it? – Put the script and all your *.nessus files into a same folder, run the script, import nss_report/report.nessus into Nessus – and there you have it, all the hosts are in one place..

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    #! /usr/bin/env python3.2

    import xml.etree.ElementTree as etree
    import shutil
    import os

    first = 1
    for fileName in os.listdir("."):
       if ".nessus" in fileName:
          print(":: Parsing", fileName)
          if first:
             mainTree = etree.parse(fileName)
             report = mainTree.find('Report')
             first = 0
          else:
             tree = etree.parse(fileName)
             for element in tree.findall('.//ReportHost'):
                report.append(element)
          print(":: => done.")

    if "nss_report" in os.listdir("."):
       shutil.rmtree("nss_report")

    os.mkdir("nss_report")
    mainTree.write("nss_report/report.nessus", encoding="utf-8", xml_declaration=True)

    If you have any questions, just drop a comment bellow..

    edit: mastahyeti made some improvements to this script, you can get it at his github

  • Removing multiple elements from a list in Python

    Removing multiple elements from a list in Python

    Let’s say you need to filter a Python list and remove all elements that match a given criteria. If you wanted to remove a single element, you could just use ‘del list[i]’ (example). But if you wanted to remove multiple elements this might be a problem since you would be modifying and iterating over the list at the same time (keeping track of list indexes can become very confusing, very fast).

    A simple solution to this problem would be to keep record of all list elements (indexes) that need to be removed, and to remove tham afterwards. Also, one other thing to be wary about is that the removal process should be done in reverse because otherwise you would shift all the elements to the ‘left’ every time you removed an element from a list and you would (again) have to keep track of list indexes.

    A simple function example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    matchingFilter = ['criteria1', 'criteria2']

    def criteriaFiltering(aList, matchingFilter):
       deletionIndexes = []
       i = 0

       for listLine in aList:
          for match in matchingFilter:
             if match in str(listLine):
                continue             
             else:
                deletionIndexes.append(i)
                break
          i += 1

       for number in reversed(deletionIndexes):
          del listLines[number]

       return aList

    This might not be the fastest ‘algorithm’ to do the job, but it works well enough for me..

Back to top