Skip to content

Commit fe4bdc9

Browse files
author
Cobin Bluth
committed
init
0 parents  commit fe4bdc9

File tree

6 files changed

+620
-0
lines changed

6 files changed

+620
-0
lines changed

Readme.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
pbin
2+
---
3+
4+
5+
this is an experimental project for putting pastes on privatebin, see here for a public directory: https://privatebin.info/directory/
6+
7+
8+
Install:
9+
---
10+
install the normal "go" way:
11+
```
12+
go get github.com/cbluth/pbin/cmd/pbin
13+
```
14+
or download a binary from the releases page:
15+
- "..."
16+
17+
Usage:
18+
---
19+
20+
Upload Paste:
21+
```
22+
$ echo "anything" | pbin
23+
https://privatebin.net/?5f9fc3956e8bc7bd#8NBafBFyqKWZrqPHiw4hC1JkL9Vx9mxEUGtXBT5wLNJF
24+
```
25+
26+
Upload Base64 Paste:
27+
```
28+
$ cat cat-meme.gif | pbin -base64
29+
https://privatebin.net/?c3dad23d043b0675#EEwJs9g3jSMC9gMHk5Gt5ptVDYpLXzCJMhP4Ufu3C3bf
30+
```
31+
32+
Download Paste:
33+
```
34+
$ pbin https://privatebin.net/?908a9812a167d638#AKQaAp7bwC9t7gLBJkLXxJt1ZQQyW4bfjnBCzbn73c95
35+
## prints to stdout
36+
```
37+
38+
Download Base64 Paste:
39+
```
40+
$ pbin -base64 https://privatebin.net/?c3dad23d043b0675#EEwJs9g3jSMC9gMHk5Gt5ptVDYpLXzCJMhP4Ufu3C3bf > cat-meme.gif
41+
```

cmd/pbin/pbin.go

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/base64"
6+
"fmt"
7+
"io"
8+
"io/ioutil"
9+
"log"
10+
"net/url"
11+
"os"
12+
"strings"
13+
14+
"github.com/cbluth/pbin"
15+
)
16+
17+
var (
18+
getURL *url.URL
19+
outFile string
20+
base64Mode bool
21+
burnAfterRead bool
22+
)
23+
24+
func init() {
25+
args := os.Args[1:]
26+
for i, arg := range args {
27+
switch arg {
28+
case "-base64", "-b64":
29+
{
30+
base64Mode = true
31+
}
32+
case "-burn":
33+
{
34+
burnAfterRead = true
35+
}
36+
case "-o":
37+
{
38+
if !(len(args) > i+1) {
39+
panic("missing output arg")
40+
}
41+
outFile = args[i+1]
42+
}
43+
}
44+
if strings.HasPrefix(arg, "https://") {
45+
u, err := url.Parse(arg)
46+
if err != nil {
47+
panic(err)
48+
}
49+
getURL = u
50+
}
51+
}
52+
}
53+
54+
func main() {
55+
err := cli()
56+
if err != nil {
57+
panic(err)
58+
}
59+
}
60+
61+
func cli() error {
62+
switch {
63+
case getURL != nil:
64+
{
65+
return get()
66+
}
67+
case getURL == nil:
68+
{
69+
return put()
70+
}
71+
}
72+
return nil
73+
}
74+
75+
func put() error {
76+
info, err := os.Stdin.Stat()
77+
if err != nil {
78+
return err
79+
}
80+
if info.Mode()&os.ModeNamedPipe == 0 {
81+
log.Fatalln("no pipe input, TODO print help")
82+
}
83+
b, err := ioutil.ReadAll(os.Stdin)
84+
if err != nil {
85+
return err
86+
}
87+
if base64Mode {
88+
b = []byte(base64.StdEncoding.EncodeToString(b))
89+
}
90+
pbin.BurnAfterReading = burnAfterRead
91+
p, err := pbin.CraftPaste(b)
92+
if err != nil {
93+
return err
94+
}
95+
ur, _, err := p.Send()
96+
if err != nil {
97+
return err
98+
}
99+
fmt.Println(ur)
100+
return nil
101+
}
102+
103+
func get() error {
104+
b, err := pbin.GetPaste(getURL)
105+
if err != nil {
106+
return err
107+
}
108+
if base64Mode {
109+
b, err = base64.StdEncoding.DecodeString(string(b))
110+
if err != nil {
111+
return err
112+
}
113+
}
114+
if outFile != "" {
115+
err = ioutil.WriteFile(outFile, b, 0644)
116+
if err != nil {
117+
return err
118+
}
119+
} else {
120+
_, err = io.Copy(os.Stdout, bytes.NewReader(b))
121+
if err != nil {
122+
return err
123+
}
124+
}
125+
return nil
126+
}

go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/cbluth/pbin
2+
3+
go 1.16
4+
5+
require (
6+
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30
7+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b
8+
)

go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30 h1:RPq056iW9QyucBAxibIUIEUaRk8FvT/QwB3YbJPbxpg=
2+
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30/go.mod h1:DVEyvP0OdbwmKHqpF7etLRKaGpAiNh+w66wVI3VzEzo=
3+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
4+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
5+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
6+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
8+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
9+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

hosts.go

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package pbin
2+
3+
import (
4+
mrand "math/rand"
5+
"net"
6+
"net/url"
7+
"time"
8+
)
9+
10+
var (
11+
hosts = processHosts()
12+
)
13+
14+
type (
15+
host struct {
16+
URL *url.URL
17+
}
18+
)
19+
20+
func processHosts() []host {
21+
hsts := []host{}
22+
for _, h := range []string{
23+
// see: https://privatebin.info/directory/
24+
"https://bin.snopyta.org/",
25+
"https://encryp.ch/note/",
26+
"https://paste.0xfc.de/",
27+
"https://paste.rosset.net/",
28+
"https://pastebin.grey.pw/",
29+
"https://privatebin.at/",
30+
"https://privatebin.silkky.cloud/",
31+
"https://zerobin.thican.net/",
32+
"https://ceppo.xyz/PrivateBin/",
33+
"https://paste.itefix.net/",
34+
"https://paste.nemeto.fr/",
35+
"https://paste.systemli.org/",
36+
"https://privatebin.net/",
37+
"https://bin.idrix.fr/",
38+
"https://bin.veracry.pt/",
39+
"https://snip.dssr.ch/",
40+
"https://paste.oneway.pro/",
41+
"https://paste.eccologic.net/",
42+
"https://paste.rollenspiel.monster/",
43+
"https://chobble.com/",
44+
"https://bin.acquia.com/",
45+
"https://p.kll.li/",
46+
"https://paste.3q3.de/",
47+
"https://pb.envs.net/",
48+
"https://paste.fizi.ca/",
49+
"https://bin.infini.fr/",
50+
"https://criminal.sh/pastes/",
51+
"https://pwnage.xyz/pastes/",
52+
"https://secure.quantumwijeeworks.ru/",
53+
"https://paste.whispers.us/",
54+
"https://тайны.миры-аномалии.рф/",
55+
"https://paste.d4v.is/",
56+
"https://bin.mezzo.moe/",
57+
"https://pastebin.aquilenet.fr/",
58+
"https://pastebin.hot-chilli.net/",
59+
"https://bin.xsden.info/",
60+
"https://pad.stoneocean.net/",
61+
"https://bin.moritz-fromm.de/",
62+
"https://extrait.facil.services/",
63+
"https://paste.i2pd.xyz/",
64+
"https://paste.momobako.com/",
65+
"https://bin.privacytools.io/",
66+
"https://paste.taiga-san.net/",
67+
"https://sw-servers.net/pb/",
68+
"https://wtf.roflcopter.fr/paste/",
69+
"https://paste.plugily.xyz/",
70+
"https://awalcon.org/private/",
71+
"https://t25b.com/",
72+
"https://paste.acab.io/",
73+
"https://zb.zerosgaming.de/",
74+
"https://p.dousse.eu/",
75+
"https://code.wt.pt/",
76+
"https://ookris.usermd.net/",
77+
"https://bin.lznet.dev/",
78+
"https://gilles.wittezaele.fr/paste/",
79+
"https://tromland.org/privatebin/",
80+
"https://www.c787898.com/paste/",
81+
"https://paste.dismail.de/",
82+
"https://paste.tuxcloud.net/",
83+
"https://files.iya.at/",
84+
"https://bin.iya.at/",
85+
"https://pb.nwsec.de/",
86+
"https://privatebin.freinetz.ch/",
87+
"https://paste.tech-port.de/",
88+
"https://bin.nixnet.services/",
89+
"https://zerobin.farcy.me/",
90+
"https://paste.tildeverse.org/",
91+
"https://paste.biocrafting.net/",
92+
"https://vim.cx/",
93+
"https://0.jaegers.net/",
94+
"https://paste.jaegers.net/",
95+
"https://bin.bissisoft.com/",
96+
"https://bin.hopon.cam/",
97+
} {
98+
u, err := url.Parse(h)
99+
if err != nil {
100+
panic(err)
101+
}
102+
hsts = append(hsts, host{u})
103+
}
104+
return hsts
105+
}
106+
107+
func pickRandom(n int) []host {
108+
mrand.Seed(time.Now().UnixNano())
109+
mix := mrand.Perm(len(hosts))
110+
hsts := []host{}
111+
for _, v := range mix[:n] {
112+
hsts = append(hsts, hosts[v])
113+
}
114+
return hsts
115+
}
116+
117+
func (h *host) ping() bool {
118+
c, err := net.DialTimeout("tcp", net.JoinHostPort(h.URL.Hostname(), "443"), 5*time.Second)
119+
if err != nil {
120+
return false
121+
}
122+
defer c.Close()
123+
return c != nil
124+
}
125+
126+
func findFastest() host {
127+
r := pickRandom(5)
128+
ping := make(chan host)
129+
go func(ch chan host) {
130+
for _, hs := range r {
131+
go func(c chan host, h host) {
132+
if h.ping() {
133+
c <- h
134+
}
135+
}(ch, hs)
136+
}
137+
}(ping)
138+
return <-ping
139+
}

0 commit comments

Comments
 (0)