Last active
June 26, 2018 02:55
-
-
Save ariankordi/c958d892634aaf15f5b2d978c426825c to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
// fasthttp doesn't like cookies on the client so we can't use it | |
"net/http" | |
"net/http/cookiejar" | |
"net/url" | |
"github.com/PuerkitoBio/goquery" | |
"io/ioutil" | |
"bytes" | |
"encoding/json" | |
"time" | |
"fmt" | |
) | |
func doError(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
var cookies, _ = cookiejar.New(nil) | |
var client = &http.Client{ | |
Jar: cookies, | |
} | |
var email []byte | |
// Init, get the email address | |
func getEmail() { | |
resp, err := client.Get("https://10minutemail.org/") | |
doError(err) | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
email = bytes.Split(bytes.Split(body, []byte("mailtext\" value=\""))[1], []byte("\""))[0] | |
} | |
func checkEmail() string { | |
resp, err := client.Get("https://10minutemail.org/mailbox.ajax.php") | |
doError(err) | |
defer resp.Body.Close() | |
doc, err := goquery.NewDocumentFromReader(resp.Body) | |
doError(err) | |
emailSubjText := "" | |
emailSubjUrl := "" | |
doc.Find("tr[style=\"font-weight: bold; cursor: pointer;\"]").Each(func(i int, s *goquery.Selection) { | |
subj := s.Find("td > a") | |
subjText := subj.Text() | |
//fmt.Println(subjText) | |
if(subjText != "Cloudinary - Email Verification") { | |
//fmt.Println("// not of Cloucinary so ill return blank") | |
return | |
} | |
emailSubjText = subjText | |
emailSubjUrl, _ = subj.Attr("href") | |
}) | |
if emailSubjText == "" { | |
//fmt.Println("// um. blank") | |
return "" | |
} | |
if(emailSubjText != "Cloudinary - Email Verification") { | |
//fmt.Println("// not of Cloucinary") | |
return "" | |
} | |
respText, err := client.Get("https://10minutemail.org/" + emailSubjUrl) | |
doError(err) | |
defer respText.Body.Close() | |
bodyText, _ := ioutil.ReadAll(respText.Body) | |
//fmt.Println(string(bodyText)) | |
hrefLink := bytes.Split(bytes.Split(bodyText, []byte("<br /><br />If the above URL"))[0], []byte("your email address by clicking the link below:<br /><br />"))[1] | |
return string(hrefLink) | |
} | |
var cloudinaryCloudName []byte | |
var cloudinaryCsrfToken []byte | |
func getCloudinaryToken() { | |
resp, err := client.Get("https://cloudinary.com/users/register/free") | |
doError(err) | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
cloudinaryCsrfToken = bytes.Split(bytes.Split(body, []byte("\" name=\"csrf-token"))[0], []byte("name=\"csrf-param\" />\n<meta content=\""))[1] | |
cloudinaryCloudName = bytes.Split(bytes.Split(body, []byte("\" id=\"customer_cloud_name"))[0], []byte("cloud_name\" data-default-value=\""))[1] | |
//fmt.Println(string(cloudinaryCloudName)) | |
} | |
func cloudinarySignup() { | |
_, err := client.PostForm("https://cloudinary.com/users/register/free", url.Values{ | |
"authenticity_token": {string(cloudinaryCsrfToken)}, | |
"plan_id": {"free"}, | |
"billing_cycle": {"monthly"}, | |
"user[name]": {"Seth Humphries"}, | |
"user[email]": {string(email)}, | |
"user[password]": {"thisisntsecure13"}, | |
"account[country]": {"US"}, | |
"account[phone]": {""}, | |
"customer[name]": {""}, | |
"account[primary_interest]": {""}, | |
"customer[cloud_name]": {string(cloudinaryCloudName)}, | |
}) | |
doError(err) | |
/*fmt.Println(resp.Header) | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println(string(body))*/ | |
} | |
type CloudinaryInfo struct { | |
Key string `json:"key"` | |
Secret string `json:"secret"` | |
Name string `json:"name"` | |
} | |
var cloudinaryAuth string | |
func getCloudinaryInfo() CloudinaryInfo { | |
resp, err := client.Get("https://cloudinary.com/console/api/v1/auth/login_from_session") | |
doError(err) | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
var authInfo map[string]interface{} | |
err = json.Unmarshal(body, &authInfo) | |
doError(err) | |
customerInfo := authInfo["customer"].(map[string]interface{}) | |
return CloudinaryInfo{ | |
Key: customerInfo["api_key"].(string), | |
Secret: customerInfo["api_secret"].(string), | |
Name: customerInfo["cloud_name"].(string), | |
} | |
} | |
func main() { | |
getEmail() | |
mailUrl, _ := url.Parse("https://10minutemail.org/") | |
cookiesList := cookies.Cookies(mailUrl) | |
for _, netCookie := range cookiesList { | |
if netCookie.Name == "PHPSESSID" { | |
fmt.Println("☆ got email " + string(email) + ", phpsessid " + netCookie.Value) | |
} | |
} | |
getCloudinaryToken() | |
fmt.Println("☆ got csrf token " + string(cloudinaryCsrfToken) + ", cloud name " + string(cloudinaryCloudName)) | |
cloudinarySignup() | |
fmt.Println("☆ signed up, checking for confirmation") | |
confirmLink := "" | |
for { | |
confirmLink = checkEmail() | |
if confirmLink == "" { | |
time.Sleep(1 * time.Second) | |
} else { | |
fmt.Println("☆ got confirm link! " + confirmLink) | |
break | |
} | |
} | |
_, err := client.Get(confirmLink) | |
doError(err) | |
fmt.Println("☆ confirmed email!") | |
infoOutput := getCloudinaryInfo() | |
fmt.Println("☆ got cloudinary info! done!") | |
output, _ := json.Marshal(infoOutput) | |
fmt.Println(string(output)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment