1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, UCS 0.7.4.0 is now available. Get it now for FREE here
    Dismiss Notice
  3. Hi there Guest ! Are you a uploader and you are looking for a way to earn from your uploads? uploadify is a file hosting platform that provides you the possibility to earn from your download without the annoying surveys. Free 10 Gb Space!
    Dismiss Notice
  4. Hey Guest, It is hard to setup a server, that is why there is a documentation to help you here
    Dismiss Notice

Clash of Clans Decryption/Encryption in python?

Discussion in 'Clash of Clans Underground' started by USBRubberDucky, Nov 1, 2015.

  1. Using clanner's clash of clans documentation project (at https://github.com/clanner/cocdp/wiki/Protocol),

    How would I utilize these scripts to send a login packet? Would I use the sockets module?

    I am also having trouble understanding what xorstream does and why it creates 512 bytes. I thought the key for the rc4's was: "fhsd6f86f67rt8fw78fw789we78r9789wer6renonce"?

    Thanks.
     
  2. Does it have the same encryption/decryption routines as the regular clash of clans client?
     
  3. Ok, I've went into it a bit in depth. The XOR stream is the rc4 streams correct? But the XOR stream is the actual encoding/decoding stream. How do I (using clash of clans documentation projects' scripts) send a login packet? Thanks
     
  4. It's an API, meaning you have to build your own method of sending it using the API's functions.

    It should be simple tho.


    I couldn't understand it at all, so I hope you can get farther than me :)

    ((Scripts will throw random errors at random times, such as 'assertion error'. TBD why.))
     
  5. Yeah, I can't really understand it either. What I maybe know that could be right so far:

    1. It initiates the streams (xor/rc4s), has something to do with 512 bytes that the script makes?
    2. Sends a login packet, then you get sent back a new key that you need to scramble with scramble7prng
    3. Then it sends userhomedata and you decode it (with the new key)?
    4. Not sure what the arguments do in xorstream.py
    5. Then you can encode/decode using the xor stream? I don't know.

    As quoted from the creator of CoCSharp:
    "The 'xorstream' is just the two RC4 stream. One for encryption and the other one decryption, you need those stream always for decrypting and encrypting the network traffic. Or to sum it up, the 'xorstream' is a stream of bytes that you must XOR with data to either encrypt or decrypt it."

    I didn't really understand what he said there, but if anybody else can, please be sure to let me know! Thank you again!

    thecheater887, you have your own program, correct? If you don't mind me asking, what language is it written in? It might be simpler. Thanks.

    If anybody has any information regarding this, it would be very helpful. If any of my steps are wrong/misinformed, feel free to correct me, and again, please share all information (even little information) about the protocol/how to do it in python. A little help goes a long way. Thanks.
     
  6. I have a lot of my own programs. Which one?

    ~~~

    1) Client inits 2 RC4 streams, with key fhsd6f86f67rt8fw78fw789we78r9789wer6re + nonce
    2) Client sends Login packet
    3) Server sends encryption packet, making the key now
    fhsd6f86f67rt8fw78fw789we78r9789wer6re + servernonce; servernonce being ver. 7 scrambled.
    4) Client kills the 2 RC4 streams created in step 1, and creates 2 new ones with the key in step 3
    5) Server sends LoginOk message
    6) Server sends OwnHomeData ((zlib compress compressed I think..?))

    Don't quote me, but, I *think* you have to xor the decrypted bytes before parsing and responding.


    Understand why I home grow everything now? :p
     
  7. Thanks, this helped a lot! The only thing I'm confused on now is the bytes that the xor stream makes (xorstream.py) and what they do.
     
  8. Also, for starting the 2 streams in python, do I use the "socket" module, and then bind one to us and connect the other to supercell's?
     
  9. For the socket, assuming you are making a proxy, you would use

    Code:
    import socket
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    s.bind(('',9339))
    s.listen(1)
    datastreamobj, IP = s.accept()
    
    ss.connect((game.clashofclans.com,9339)) #gamea for android, game for iOS
    
    Probably has a few bugs, but should be easily fixable since I can't run it atm to test, but that is the core of everything.


    Im not 100% sure of when to use the xor stream, however, it will generate the first 512 bytes on import. Nothing you can or need to do about that.
     
  10. I'm not using a proxy, so I guess just socket.connect would work. As for the xor stream, are you implementing it currently (in your program), or is it not needed at all, and you just decode with rc4? Thanks
     
  11. I'm still trying to figure that one out. I'll do some tests and get back to you on that one.
     
  12. Thanks. I really appreciate your help. It means a lot to me.
     
  13. Have you started a proxy, or are you still in the research phase?
     
  14. Well, I'm not doing a proxy. I want to make an automation system that uses only packets to interact with supercell's servers. Going into this, I wanted a low power system to run it on, without needing the gui.
     
  15. Here's the thing;

    You need to build a proxy so you can properly parse and handle whatever else you're doing. There's no avoiding it.


    What was the automation system supposed to do?
     
  16. #17 USBRubberDucky, Nov 2, 2015
    Last edited: Nov 2, 2015
    Login and collect resources is what it needed to do. It is possible, however. One example of this is CoCSharp.Server on github, which was able to login to my account with the pre-captured credentials and tell me what my village consisted of (buildings). Thanks!
     
  17. Do you have skype? It would be easier than going back and forth here.

    If not; by "log in and collect resources" you mean connect, and simulate tapping on the mines I would assume?
     
  18. Yes, that's what I mean. I can contact you later with Skype st about 3pm est. I will give you my Skype then, as I don't know the exact name now. Thanks!
     
  19. I don't think he wants to to "tap" anywhere...
    ...just exchange packets with the server.
    I'm not sure how the client interprets out taps on the screen, but I believe it's just a packet containing some collector's ID.

    Anyway, I also think the "proxy way" is the best one.
    Implementing such thing would lead to much more than only "login&collect".
    Probably xmodgames implement a similar way, when, for example, it searches for bases.
    • Intercept/evaluate enemy-base layout/data packet
    • send "next" packet if not enough resources.
    That's why it is so fast skipping bases (no crap imgsearch involved).
     

Share This Page