-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cobin Bluth
committed
Apr 30, 2021
0 parents
commit fe4bdc9
Showing
6 changed files
with
620 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
pbin | ||
--- | ||
|
||
|
||
this is an experimental project for putting pastes on privatebin, see here for a public directory: https://privatebin.info/directory/ | ||
|
||
|
||
Install: | ||
--- | ||
install the normal "go" way: | ||
``` | ||
go get github.com/cbluth/pbin/cmd/pbin | ||
``` | ||
or download a binary from the releases page: | ||
- "..." | ||
|
||
Usage: | ||
--- | ||
|
||
Upload Paste: | ||
``` | ||
$ echo "anything" | pbin | ||
https://privatebin.net/?5f9fc3956e8bc7bd#8NBafBFyqKWZrqPHiw4hC1JkL9Vx9mxEUGtXBT5wLNJF | ||
``` | ||
|
||
Upload Base64 Paste: | ||
``` | ||
$ cat cat-meme.gif | pbin -base64 | ||
https://privatebin.net/?c3dad23d043b0675#EEwJs9g3jSMC9gMHk5Gt5ptVDYpLXzCJMhP4Ufu3C3bf | ||
``` | ||
|
||
Download Paste: | ||
``` | ||
$ pbin https://privatebin.net/?908a9812a167d638#AKQaAp7bwC9t7gLBJkLXxJt1ZQQyW4bfjnBCzbn73c95 | ||
## prints to stdout | ||
``` | ||
|
||
Download Base64 Paste: | ||
``` | ||
$ pbin -base64 https://privatebin.net/?c3dad23d043b0675#EEwJs9g3jSMC9gMHk5Gt5ptVDYpLXzCJMhP4Ufu3C3bf > cat-meme.gif | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/cbluth/pbin" | ||
) | ||
|
||
var ( | ||
getURL *url.URL | ||
outFile string | ||
base64Mode bool | ||
burnAfterRead bool | ||
) | ||
|
||
func init() { | ||
args := os.Args[1:] | ||
for i, arg := range args { | ||
switch arg { | ||
case "-base64", "-b64": | ||
{ | ||
base64Mode = true | ||
} | ||
case "-burn": | ||
{ | ||
burnAfterRead = true | ||
} | ||
case "-o": | ||
{ | ||
if !(len(args) > i+1) { | ||
panic("missing output arg") | ||
} | ||
outFile = args[i+1] | ||
} | ||
} | ||
if strings.HasPrefix(arg, "https://") { | ||
u, err := url.Parse(arg) | ||
if err != nil { | ||
panic(err) | ||
} | ||
getURL = u | ||
} | ||
} | ||
} | ||
|
||
func main() { | ||
err := cli() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func cli() error { | ||
switch { | ||
case getURL != nil: | ||
{ | ||
return get() | ||
} | ||
case getURL == nil: | ||
{ | ||
return put() | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func put() error { | ||
info, err := os.Stdin.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
if info.Mode()&os.ModeNamedPipe == 0 { | ||
log.Fatalln("no pipe input, TODO print help") | ||
} | ||
b, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
return err | ||
} | ||
if base64Mode { | ||
b = []byte(base64.StdEncoding.EncodeToString(b)) | ||
} | ||
pbin.BurnAfterReading = burnAfterRead | ||
p, err := pbin.CraftPaste(b) | ||
if err != nil { | ||
return err | ||
} | ||
ur, _, err := p.Send() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(ur) | ||
return nil | ||
} | ||
|
||
func get() error { | ||
b, err := pbin.GetPaste(getURL) | ||
if err != nil { | ||
return err | ||
} | ||
if base64Mode { | ||
b, err = base64.StdEncoding.DecodeString(string(b)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
if outFile != "" { | ||
err = ioutil.WriteFile(outFile, b, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
_, err = io.Copy(os.Stdout, bytes.NewReader(b)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/cbluth/pbin | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30 | ||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30 h1:RPq056iW9QyucBAxibIUIEUaRk8FvT/QwB3YbJPbxpg= | ||
github.com/gearnode/base58 v0.0.0-20200201175139-69e2d70f0e30/go.mod h1:DVEyvP0OdbwmKHqpF7etLRKaGpAiNh+w66wVI3VzEzo= | ||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= | ||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package pbin | ||
|
||
import ( | ||
mrand "math/rand" | ||
"net" | ||
"net/url" | ||
"time" | ||
) | ||
|
||
var ( | ||
hosts = processHosts() | ||
) | ||
|
||
type ( | ||
host struct { | ||
URL *url.URL | ||
} | ||
) | ||
|
||
func processHosts() []host { | ||
hsts := []host{} | ||
for _, h := range []string{ | ||
// see: https://privatebin.info/directory/ | ||
"https://bin.snopyta.org/", | ||
"https://encryp.ch/note/", | ||
"https://paste.0xfc.de/", | ||
"https://paste.rosset.net/", | ||
"https://pastebin.grey.pw/", | ||
"https://privatebin.at/", | ||
"https://privatebin.silkky.cloud/", | ||
"https://zerobin.thican.net/", | ||
"https://ceppo.xyz/PrivateBin/", | ||
"https://paste.itefix.net/", | ||
"https://paste.nemeto.fr/", | ||
"https://paste.systemli.org/", | ||
"https://privatebin.net/", | ||
"https://bin.idrix.fr/", | ||
"https://bin.veracry.pt/", | ||
"https://snip.dssr.ch/", | ||
"https://paste.oneway.pro/", | ||
"https://paste.eccologic.net/", | ||
"https://paste.rollenspiel.monster/", | ||
"https://chobble.com/", | ||
"https://bin.acquia.com/", | ||
"https://p.kll.li/", | ||
"https://paste.3q3.de/", | ||
"https://pb.envs.net/", | ||
"https://paste.fizi.ca/", | ||
"https://bin.infini.fr/", | ||
"https://criminal.sh/pastes/", | ||
"https://pwnage.xyz/pastes/", | ||
"https://secure.quantumwijeeworks.ru/", | ||
"https://paste.whispers.us/", | ||
"https://тайны.миры-аномалии.рф/", | ||
"https://paste.d4v.is/", | ||
"https://bin.mezzo.moe/", | ||
"https://pastebin.aquilenet.fr/", | ||
"https://pastebin.hot-chilli.net/", | ||
"https://bin.xsden.info/", | ||
"https://pad.stoneocean.net/", | ||
"https://bin.moritz-fromm.de/", | ||
"https://extrait.facil.services/", | ||
"https://paste.i2pd.xyz/", | ||
"https://paste.momobako.com/", | ||
"https://bin.privacytools.io/", | ||
"https://paste.taiga-san.net/", | ||
"https://sw-servers.net/pb/", | ||
"https://wtf.roflcopter.fr/paste/", | ||
"https://paste.plugily.xyz/", | ||
"https://awalcon.org/private/", | ||
"https://t25b.com/", | ||
"https://paste.acab.io/", | ||
"https://zb.zerosgaming.de/", | ||
"https://p.dousse.eu/", | ||
"https://code.wt.pt/", | ||
"https://ookris.usermd.net/", | ||
"https://bin.lznet.dev/", | ||
"https://gilles.wittezaele.fr/paste/", | ||
"https://tromland.org/privatebin/", | ||
"https://www.c787898.com/paste/", | ||
"https://paste.dismail.de/", | ||
"https://paste.tuxcloud.net/", | ||
"https://files.iya.at/", | ||
"https://bin.iya.at/", | ||
"https://pb.nwsec.de/", | ||
"https://privatebin.freinetz.ch/", | ||
"https://paste.tech-port.de/", | ||
"https://bin.nixnet.services/", | ||
"https://zerobin.farcy.me/", | ||
"https://paste.tildeverse.org/", | ||
"https://paste.biocrafting.net/", | ||
"https://vim.cx/", | ||
"https://0.jaegers.net/", | ||
"https://paste.jaegers.net/", | ||
"https://bin.bissisoft.com/", | ||
"https://bin.hopon.cam/", | ||
} { | ||
u, err := url.Parse(h) | ||
if err != nil { | ||
panic(err) | ||
} | ||
hsts = append(hsts, host{u}) | ||
} | ||
return hsts | ||
} | ||
|
||
func pickRandom(n int) []host { | ||
mrand.Seed(time.Now().UnixNano()) | ||
mix := mrand.Perm(len(hosts)) | ||
hsts := []host{} | ||
for _, v := range mix[:n] { | ||
hsts = append(hsts, hosts[v]) | ||
} | ||
return hsts | ||
} | ||
|
||
func (h *host) ping() bool { | ||
c, err := net.DialTimeout("tcp", net.JoinHostPort(h.URL.Hostname(), "443"), 5*time.Second) | ||
if err != nil { | ||
return false | ||
} | ||
defer c.Close() | ||
return c != nil | ||
} | ||
|
||
func findFastest() host { | ||
r := pickRandom(5) | ||
ping := make(chan host) | ||
go func(ch chan host) { | ||
for _, hs := range r { | ||
go func(c chan host, h host) { | ||
if h.ping() { | ||
c <- h | ||
} | ||
}(ch, hs) | ||
} | ||
}(ping) | ||
return <-ping | ||
} |
Oops, something went wrong.