https://upx.github.io/Until now, we've used python as the primary programming language without realizing that... There's a chance the target system won't have python installed on it. Plus, the scripts won't be executable. Yeah sure, you can add the good 'ol shebang at the top:
#!/bin/env python3
But that won't be good enough even if the target has python installed. Can you guess why? Well, the program will still be written in python and the victim can read through it and probably determine that it's malicious. That's where packers are helpful. You can pack an executable with one of those so as to avoid detection. Python scripts themselves can be "converted" to executables using tools like: pyinstaller or py2exe. But those aren't considered packers.
Also, here's a very good repo that has a lot of content on packing:
I'll take one or two examples from each of the above and showcase the packing process. First in the line is UPX:
Packing Malware With UPX
Let's first get some simple "malware" to pack...
First, we need a payload. Let's take a zip bomb (see Zip Bombs):
$ # NOTE: Make necessary changes in the zipbomb.go file
$ ./payloadgen.bash 10000 40
$ go-bindata -o payload.go payload_40.zip
$ # Save this for later...
Now, let's write a program that can cover this up. For this example, I've kindly yoinked some code from the walk project over at github...
// Copyright 2017 The Walk Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// This example demonstrates the status bar, including a size gripper// attached to the bottom of the main window.// The status bar has two items, one is dynamically updated and one includes an icon.packagemainimport ("log""github.com/lxn/walk" . "github.com/lxn/walk/declarative")funcmain() { icon1, err := walk.NewIconFromFile("../img/check.ico")if err !=nil { log.Fatal(err) } icon2, err := walk.NewIconFromFile("../img/stop.ico")if err !=nil { log.Fatal(err) }var sbi *walk.StatusBarItemMainWindow{ Title: "Walk Statusbar Example", MinSize: Size{600, 200}, Layout: VBox{MarginsZero: true}, StatusBarItems: []StatusBarItem{StatusBarItem{ AssignTo: &sbi, Icon: icon1, Text: "click", Width: 80, OnClicked: func() {if sbi.Text() =="click" { sbi.SetText("again") sbi.SetIcon(icon2) } else { sbi.SetText("click") sbi.SetIcon(icon1) } }, },StatusBarItem{ Text: "left", ToolTipText: "no tooltip for me", },StatusBarItem{ Text: "\tcenter", },StatusBarItem{ Text: "\t\tright", },StatusBarItem{ Icon: icon1, ToolTipText: "An icon with a tooltip", }, }, }.Run()}
We'll of course need to modify this to make it plant and set off the payload:
Also, it'll also be a good idea to bake in a nice ol' UAC request. Refer to this post on SO.
Now that we have our payload ready, we can pack this sucker with UPX:
$ upx --best -f -o notavirus.exe setup.exe
I'd love to write sections on other malware and commercial packers, but unfortunately, I'm broke. So if you wanna add a section on those, please feel free to do so by making a PR.