如何从pastebin访问原始私有粘贴?

时间:2012-11-04 23:12:07

标签: lua pastebin

我知道如何使用pastebin API生成用户密钥,但是如何使用此用户密钥访问原始私有粘贴?

我正在使用Lua。

3 个答案:

答案 0 :(得分:1)

获取原始粘贴bin输出不是 Pastebin API的一部分:

  

此选项实际上不是我们API的一部分,但您可能仍希望使用它。要获得粘贴的RAW输出,您可以使用我们的RAW数据输出URL:

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

只需在该网址末尾添加 paste_key 即可获得RAW输出。

由于私人粘贴只能由创建它们的用户看到,我的猜测是他们使用logincookie进行身份验证。在这种情况下,您需要使用HTTP请求发送它。


关于在Lua中实现这一点,(因为你还没有说过你正在使用哪个库)我将要出去推荐LuaSocket中的HTTP module或精彩的Luvit({{3} })。

答案 1 :(得分:1)

以下是适合您的代码示例:

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

答案 2 :(得分:0)

我知道回答这个问题有点迟,但我希望这会对以后的某些人有所帮助。

如果要访问原始私有粘贴,首先需要列出用户创建的粘贴。这是API的一部分。这需要用户登录。

  

使用此API,您可以列出特定用户创建的所有粘贴。   您需要向以下URL发送有效的POST请求才能访问   数据:

http://pastebin.com/api/api_post.php  

您将获得的响应将是XML响应,如下所示:

<paste>
    <paste_key>0b42rwhf</paste_key>
    <paste_date>1297953260</paste_date>
    <paste_title>javascript test</paste_title>
    <paste_size>15</paste_size>
    <paste_expire_date>1297956860</paste_expire_date>
    <paste_private>0</paste_private>
    <paste_format_long>JavaScript</paste_format_long>
    <paste_format_short>javascript</paste_format_short>
    <paste_url>http://pastebin.com/0b42rwhf</paste_url>
    <paste_hits>15</paste_hits>
</paste>  

完成后,解析XML以获取paste_keypaste_private。您需要检查paste_private的值,因为您只需要私有粘贴。文档说:

  

我们有3个有效值可供您使用   &#39; api_paste_private&#39;参数:

0 = Public
1 = Unlisted
2 = Private (only allowed in combination with api_user_key, as you have to be logged into your account to access the paste)  

因此,如果您的粘贴的paste_private设置为2,请获取paste_key

获得paste_key后,请使用API​​调用获取RAW粘贴。获得私有粘贴的粘贴密钥后,无需用户名或密码。

玩得开心!