Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Aug 31, 2021
1 parent 9848ce6 commit 71f1d08
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 26 deletions.
18 changes: 15 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ Vagrant.configure("2") do |config|
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
$script = <<-'SCRIPT'
add-apt-repository ppa:longsleep/golang-backports
apt-get update && apt-get upgrade -y
apt-get install golang-go make cmake gcc gcc-multilib g++-multilib gdb checksec -y
apt-get install golang-go make cmake gcc gcc-multilib g++-multilib \
gdb checksec git python2 python3 python3-pip \
python3-dev libssl-dev libffi-dev build-essential -y
python3 -m pip install -q --upgrade pip
python3 -m pip install -q --upgrade pwntools
/home/vagrant/gopwn/scripts/install_capstone.sh
/home/vagrant/gopwn/scripts/install_keystone.sh
SHELL
git clone -q https://github.com/longld/peda.git /opt/peda
echo "# gdb extensions:" >> /home/vagrant/.bashrc
echo "alias peda=\"gdb -iex 'source /opt/peda/peda.py' --nh -q\"" >> /home/vagrant/.bashrc
SCRIPT

config.vm.provision "shell", inline: $script
end
11 changes: 9 additions & 2 deletions binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"os"
"regexp"

"github.com/ianlancetaylor/demangle"
)

type BinaryReader interface {
Expand Down Expand Up @@ -107,12 +109,14 @@ type StringsOptions struct {
Max int
Regex func(min, max int) *regexp.Regexp
Sections []string
Demangle bool
}

func parseStrings(sections []dataReader, optFns ...func(o *StringsOptions)) []string {
options := StringsOptions{
Min: 4,
Max: 100,
Min: 4,
Max: 100,
Demangle: false,
Regex: func(min, max int) *regexp.Regexp {
return regexp.MustCompile(fmt.Sprintf("([\x20-\x7E]{%d}[\x20-\x7E]*)", min))
},
Expand All @@ -139,6 +143,9 @@ func parseStrings(sections []dataReader, optFns ...func(o *StringsOptions)) []st
}
str := string(b)
if validString.MatchString(str) {
if options.Demangle {
str = demangle.Filter(str)
}
strs = append(strs, str)
}
}
Expand Down
6 changes: 3 additions & 3 deletions elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ func (e *ELF) Close() error {
return e.file.Close()
}

func (e *ELF) DumpHeader(hdr interface{}) {
func (e *ELF) DumpHeader() {
fmt.Println("-------------------------- Elf Header ------------------------")
switch e.file.Class {
case elf.ELFCLASS64:
h := e.hdr.(elf.Header64)
h := e.hdr.(*elf.Header64)
fmt.Printf("Magic: % x\n", h.Ident)
fmt.Printf("Class: %s\n", elf.Class(h.Ident[elf.EI_CLASS]))
fmt.Printf("Data: %s\n", elf.Data(h.Ident[elf.EI_DATA]))
Expand All @@ -227,7 +227,7 @@ func (e *ELF) DumpHeader(hdr interface{}) {
fmt.Printf("Number of Section Header Entries: %d\n", h.Shnum)
fmt.Printf("Index of Section Header string table: %d\n", h.Shstrndx)
case elf.ELFCLASS32:
h := e.hdr.(elf.Header32)
h := e.hdr.(*elf.Header32)
fmt.Printf("Magic: % x\n", h.Ident)
fmt.Printf("Class: %s\n", elf.Class(h.Ident[elf.EI_CLASS]))
fmt.Printf("Data: %s\n", elf.Data(h.Ident[elf.EI_DATA]))
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/fatih/color v1.12.0
github.com/ianlancetaylor/demangle v0.0.0-20210822211355-471757278659
github.com/keystone-engine/keystone v0.0.0-20210720183742-1475885daa7e
github.com/knightsc/gapstone v4.0.1+incompatible
github.com/manifoldco/promptui v0.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20210822211355-471757278659 h1:rAo0tEfzvHqxoJx69bXpFm0Qv8DaXY9jnqkpUf8gf04=
github.com/ianlancetaylor/demangle v0.0.0-20210822211355-471757278659/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down
5 changes: 2 additions & 3 deletions tube/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ func (l *Listener) WaitForConnection() error {
return err
}
l.tube = tube{
stdin: c,
stdout: c,
stderr: c,
in: c,
out: c,
}
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions tube/process.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tube

import (
"io"
"os"
"os/exec"
)
Expand Down Expand Up @@ -28,15 +29,15 @@ func NewProcess(argv []string, optFns ...func(o *ProcessOptions)) (*Process, err
cmd.Env = append(os.Environ(), options.Env...)
cmd.Dir = options.Dir

stdin, err := cmd.StdinPipe()
in, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
stdout, err := cmd.StdoutPipe()
stdOut, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
stdErr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
Expand All @@ -47,9 +48,8 @@ func NewProcess(argv []string, optFns ...func(o *ProcessOptions)) (*Process, err
return &Process{
cmd: cmd,
tube: tube{
stdin: stdin,
stdout: stdout,
stderr: stderr,
in: in,
out: io.NopCloser(io.MultiReader(stdOut, stdErr)),
newLine: options.NewLine,
},
}, nil
Expand Down
5 changes: 2 additions & 3 deletions tube/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func NewRemote(network, addr string) (*Remote, error) {
return &Remote{
conn: c,
tube: tube{
stdin: c,
stdout: c,
stderr: c,
in: c,
out: c,
},
}, nil
}
Expand Down
11 changes: 5 additions & 6 deletions tube/tube.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ import (
)

type tube struct {
stdin io.WriteCloser
stdout io.ReadCloser
stderr io.ReadCloser
in io.WriteCloser
out io.ReadCloser
newLine byte
}

// SendLine sends data with a trailing newline character
func (t *tube) SendLine(input interface{}) (int, error) {
b := Bytes(input)
b = append(b, t.NewLine())
return t.stdin.Write(b)
return t.in.Write(b)
}

// RecvN receives a specified number of bytes
func (t *tube) RecvN(n int) ([]byte, error) {
b := make([]byte, n)
rn, err := t.stdout.Read(b)
rn, err := t.out.Read(b)
if err != nil {
return nil, err
}
Expand All @@ -40,7 +39,7 @@ func (t *tube) RecvUntil(needle []byte, drop bool) ([]byte, error) {
// RecvUntilWithContext receives data until the specified sequence of bytes is detected or the context is done.
func (t *tube) RecvUntilWithContext(ctx context.Context, needle []byte, drop bool) ([]byte, error) {
data := make([]byte, len(needle))
b := bufio.NewReader(t.stdout)
b := bufio.NewReader(t.out)

_, err := io.ReadFull(b, data)
if err != nil {
Expand Down

0 comments on commit 71f1d08

Please sign in to comment.