Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [Python] NeoAccount Class (include AMF requests)

  1. #1

    Joined
    Jun 2012
    Posts
    131
    Userbars
    1
    Thanks
    21
    Thanked
    50/22
    DL/UL
    37/0
    Mentioned
    22 times
    Time Online
    4d 17h 8m
    Avg. Time Online
    1m

    [Python] NeoAccount Class (includes AMF requests)

    Written in Python 2.7

    Code:
    import urllib2, urllib, cookielib
    import StringIO, gzip
    
    
    class NeoAccount:
    
        d = 'http://www.neopets.com'
        headers = [('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1'),
                    ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
                    ('Accept-Language', 'en-us,en;q=0.5'),
                    ('Accept-Encoding', 'gzip, deflate')]
        
        def __init__(self, user, pw, proxy = None):
            self.user = user
            self.pw = pw
            self.proxy = proxy
            self.referer = ''
            
            cj = cookielib.LWPCookieJar()
            cookie_handler = urllib2.HTTPCookieProcessor(cj)
            
            if proxy != None:
                proxy_handler = urllib2.ProxyHandler({'http': 'http://' + proxy + '/'})
                self.opener = urllib2.build_opener(proxy_handler, cookie_handler)
            else:
                self.opener = urllib2.build_opener(cookie_handler)
    
        def __str__(self):
            return '%s:%s' % (self.user, self.pw)
    
        def get(self, url, referer = '', readable = True):
            if url[0] == '/':
                url = self.d + url
            if referer == '':
                referer = self.referer
            self.opener.addheaders = [('Referer', referer)]  + self.headers
            res = self.opener.open(url)
            self.referer = res.geturl()
            if readable:
                return self.readable(res)
            else:
                return res
    
        def post(self, url, data, referer = '', readable = True):
            if url[0] == '/':
                url = self.d + url
            if referer == '':
                referer = self.referer
            self.opener.addheaders = [('Content-Type', 'application/x-www-form-urlencoded'),
                                      ('Referer', referer)] + self.headers
            res = self.opener.open(url, urllib.urlencode(data))
            self.referer = res.geturl()
            if readable:
                return self.readable(res)
            else:
                return res
    
        def amf(self, packet, gateway = 'http://services.neopets.com/amfphp/gateway.php', referer = ''):
            if referer == '':
                referer = self.referer
            self.opener.addheaders = [('Content-Type', 'application/x-amf'),
                                      ('Referer', referer)] + self.headers
            res = self.opener.open(gateway, packet)
            return res.read()
    
        def login(self):
            res = self.get('/index.phtml')
            res = self.post('/login.phtml', {'username': self.user,
                                             'password': self.pw,
                                             'destination': "/index.phtml"}, readable = False)
            if 'badpassword' in res.geturl():
                return False, 'Bad password'
            elif 'hello' in res.geturl():
                return False, 'Birthday locked'
            elif 'login' in res.geturl():
                return False, 'Frozen'
            elif 'index' in res.geturl():
                return True, 'Logged in'
    
        def readable(self, data):
            if 'gzip' in str(data.info()):
                return gzip.GzipFile(fileobj=StringIO.StringIO(data.read())).read()
            else:
                return data.read()
    Code:
    >>> acc = NeoAccount('username', 'password')
    >>> acc .login()
    (True, 'Logged in')
    >>> html = acc.get('/objects.phtml?type=inventory')
    In post, data should be a dictionary. In amf, packet is a string representing the packet.

    This was my first time writing anything to actually navigate neopets so let me know if I missed a crucial feature or if I could add anything to make it more secure/easier to use. I was just writing something to make use of rare's pin crack idea but it seems the idea is patched up. I figured I might as well share some of the code so that the time doesn't go to waste '
    Last edited by ikakk; 09-11-2012 at 08:40 PM.

  2. The Following 8 Users Say Thank You to ikakk For This Useful Post:

    Auroz (08-12-2015),DarkByte (10-01-2013),Ghosts (12-10-2014),Graff (09-11-2012),james087 (09-11-2012),mt5o5bd (02-05-2014),Reemer (09-11-2012),Water (10-16-2014)

  3. #2

    Joined
    Jul 2012
    Posts
    717
    Userbars
    3
    Thanks
    105
    Thanked
    201/114
    DL/UL
    24/0
    Mentioned
    88 times
    Time Online
    22d 22h 4m
    Avg. Time Online
    7m
    I have no idea what I'm looking at. Is this anything a normal non-coder like me can use?

  4. #3

    Joined
    Jun 2012
    Posts
    131
    Userbars
    1
    Thanks
    21
    Thanked
    50/22
    DL/UL
    37/0
    Mentioned
    22 times
    Time Online
    4d 17h 8m
    Avg. Time Online
    1m
    Not really. Hopefully it will inspire some coders to make new programs though!

    EDIT: Updated AMF to allow custom gateways since some places have their own. Check the headers of the packet you are spoofing to see what you should use.
    Last edited by ikakk; 09-11-2012 at 02:07 PM.

  5. The Following User Says Thank You to ikakk For This Useful Post:

    james087 (09-11-2012)

  6. #4
    james087's Avatar
    Joined
    Sep 2012
    Posts
    64
    Userbars
    1
    Thanks
    20
    Thanked
    7/5
    DL/UL
    10/0
    Mentioned
    1 time
    Time Online
    N/A
    Avg. Time Online
    N/A
    Quote Originally Posted by ikakk View Post
    Not really. Hopefully it will inspire some coders to make new programs though!
    Thanks! I'm pretty sure I'll be able to use bits of this in the near future. I haven't 100% committed to python yet, but the way things are headed I think I will be.

  7. #5

    Joined
    Jun 2012
    Posts
    131
    Userbars
    1
    Thanks
    21
    Thanked
    50/22
    DL/UL
    37/0
    Mentioned
    22 times
    Time Online
    4d 17h 8m
    Avg. Time Online
    1m
    Quote Originally Posted by james087 View Post
    Thanks! I'm pretty sure I'll be able to use bits of this in the near future. I haven't 100% committed to python yet, but the way things are headed I think I will be.
    It's a great language to get into things with. Use python 2 by the way not python 3. Let me know if you want help understanding why I did anything the way I did in this once you get started!

    Thanks for the rep by the way.

  8. The Following 2 Users Say Thank You to ikakk For This Useful Post:

    james087 (09-11-2012),Ryan~ (09-11-2012)

  9. #6

    Joined
    Jun 2012
    Posts
    131
    Userbars
    1
    Thanks
    21
    Thanked
    50/22
    DL/UL
    37/0
    Mentioned
    22 times
    Time Online
    4d 17h 8m
    Avg. Time Online
    1m
    @(you need an account to see links)

    Yep. Pretty easy in python.

    edit: 99% sure cookies will work with multiple logins. I'll try it out sometime soon and get back to you.
    edit 2: Checked it out and I actually set a shared cookiejar so the cookie ended up getting replaced by the new login when you tried running two accounts in the same program. I made a few quick changes and gave each instance their own cookiejar so it now works with multiple accounts.
    Last edited by ikakk; 09-11-2012 at 05:21 PM.

  10. The Following User Says Thank You to ikakk For This Useful Post:

    j03 (09-12-2012)

  11. #7
    txtsd's Avatar
    Joined
    Dec 2012
    Posts
    642
    Userbars
    7
    Thanks
    538
    Thanked
    327/146
    DL/UL
    60/2
    Mentioned
    91 times
    Time Online
    31d 8h 56m
    Avg. Time Online
    10m
    Code:
            elif 'hello' in res.geturl():
                return False, 'Birthday locked'
    This is the bane of my existence.
    Is there no way to input a user's birthday and use that to login if an account is birthday locked?

  12. #8
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,720
    Userbars
    166
    Thanks
    5,906
    Thanked
    33,076/6,608
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 4h 55m
    Avg. Time Online
    3h 13m
    Quote Originally Posted by txtsd View Post
    Code:
            elif 'hello' in res.geturl():
                return False, 'Birthday locked'
    This is the bane of my existence.
    Is there no way to input a user's birthday and use that to login if an account is birthday locked?
    Of course, instead of returning a false value, just add a request to login again but with the birthday included in the POST data. If you dunno this try using WireShark or Fiddler, something that shows the variables with their values sent via browser.
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  13. #9
    txtsd's Avatar
    Joined
    Dec 2012
    Posts
    642
    Userbars
    7
    Thanks
    538
    Thanked
    327/146
    DL/UL
    60/2
    Mentioned
    91 times
    Time Online
    31d 8h 56m
    Avg. Time Online
    10m
    Quote Originally Posted by Infamous Joe View Post
    Of course, instead of returning a false value, just add a request to login again but with the birthday included in the POST data. If you dunno this try using WireShark or Fiddler, something that shows the variables with their values sent via browser.
    It's time to learn how to use WireShark! Do you know the variables and values yourself?

  14. #10
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,720
    Userbars
    166
    Thanks
    5,906
    Thanked
    33,076/6,608
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 4h 55m
    Avg. Time Online
    3h 13m
    Quote Originally Posted by txtsd View Post
    It's time to learn how to use WireShark! Do you know the variables and values yourself?
    Nah, that's like asking me if I know the URL to auction an item from my inventory for example.
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •