Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access a raw private paste from pastebin?

Tags:

lua

pastebin

I know how to generate a user key using the pastebin API, but how can I use this userkey to access a raw private paste?

I am using Lua for this.

like image 777
daxvena Avatar asked Nov 04 '12 23:11

daxvena


2 Answers

Obtaining the raw paste bin output is not part of of the Pastebin API:

This option is actually not part of our API, but you might still want to use it. To get the RAW output of a paste you can use our RAW data output URL:

http://pastebin.com/raw.php?i=

Simply add the paste_key at the end of that URL and you will get the RAW output.

Since private pastes can only be seen by the user who created them, my guess is that they use the logincookie for authentication. In that case, you'll need to send it with the HTTP request.


In respect to implementing this in Lua, (since you haven't said which library you're using) I'm gonna go forth and recommend the HTTP module in LuaSocket or the wonderful Luvit (http://luvit.io).

like image 79
MBlanc Avatar answered Sep 22 '22 16:09

MBlanc


Here is a ready example of the code for you:

local https = require('ssl.https')
    https.TIMEOUT= 15

    local private_raw_url="https://pastebin.com/raw/YOURPAGE" -- Change raw link
    local user_name, user_password = "USER", "PASS"           -- and user with password

    local request_body = "submit_hidden=submit_hidden&user_name=".. user_name .. "&user_password=" .. user_password .. "&submit=Login"

    local resp = {}
    local res, code, headers, status = https.request ( {
                            method = 'POST',
                            url = "https://pastebin.com/login",
                            headers = { 
                              Host = "pastebin.com", 
                              ["Content-Type"] = "application/x-www-form-urlencoded",
                              ["Content-Length"] = string.len(request_body), 
                              Connection = "keep-alive",
                            }, 
                            source = ltn12.source.string(request_body),
                            sink = ltn12.sink.table(resp),
                            protocol =  "tlsv1", 
                            verify = "none",
                            verifyext = {"lsec_continue", "lsec_ignore_purpose"},
                            options = { "all", "no_sslv2", "no_sslv3" } 
                        } )
    if not headers['set-cookie']:find('pastebin_user') then 
           print('bad login')
           return
    end
    resp={}
    local cookie = headers['set-cookie'] or ''
    local cookie1, cookie2, cookie3 = cookie:match("(__cfduid=%w+; ).*(PHPSESSID=%w+; ).*(pastebin_user=%w+; )" )   
    if cookie1 and cookie2 and cookie3 then
            cookie = cookie1 .. cookie2 .. cookie3
            body, code, headers= https.request{
                url = private_raw_url ,
                headers = { 
                            --Host = "pastebin.com", 
                            ['Cookie'] = cookie,
                            ['Connection'] = 'keep-alive'
                                },         
                sink = ltn12.sink.table(resp)     
             }  

            if code~=200 then  return  end 

           print( table.concat(resp) )
    else
        print("error match cookies!" )
    end
like image 38
Mike V. Avatar answered Sep 24 '22 16:09

Mike V.