Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KissAnime encryption change #53

Open
RexfelisLOC opened this issue Mar 15, 2017 · 82 comments
Open

KissAnime encryption change #53

RexfelisLOC opened this issue Mar 15, 2017 · 82 comments
Assignees
Labels
Milestone

Comments

@RexfelisLOC
Copy link

Looks like KissAnime has a new decryption function called "ovelWrap". It seems to be encoded as the following:

function ovelWrap(_0x7b4ax13) {
var _0x7b4axe = null;
try {
var _0x7b4ax10 = CryptoJS[_0x59b3[0]][_0x59b3[24]][_0x59b3[23]]({
ciphertext : CryptoJS[_0x59b3[22]][_0x59b3[21]]_0x59b3[20]
}),
_0x7b4ax7 = CryptoJS[_0x59b3[30]][_0x59b3[29]](_0x7b4ax10, key, {
mode : CryptoJS[_0x59b3[26]][_0x59b3[25]],
iv : iv,
padding : CryptoJS[_0x59b3[28]][_0x59b3[27]]
});
return _0x7b4axe = _0x7b4ax7.toString(CryptoJS[_0x59b3[22]].Utf8)
} catch (p) {
alert(p + _0x7b4ax13)
}
}
var bkZ = _0x59b3[31], skH = _0x59b3[32], iv, key;
iv = CryptoJS[_0x59b3[22]][_0x59b3[33]]_0x59b3[20], key = CryptoJS.SHA256(skH)

How do you decode javascript like the above?

@RexfelisLOC
Copy link
Author

Found a JS deobfuscator:

function ovelWrap(_0x7b4ax13) {
var _0x7b4axe = null;
try {
var _0x7b4ax10 = CryptoJS['lib']['CipherParams']['create']({
ciphertext: CryptoJS['enc']['Base64']'parse'
}),
_0x7b4ax7 = CryptoJS['AES']['decrypt'](_0x7b4ax10, key, {
mode: CryptoJS['mode']['CBC'],
iv: iv,
padding: CryptoJS['pad']['Pkcs7']
});
return _0x7b4axe = _0x7b4ax7.toString(CryptoJS['enc'].Utf8)
} catch (p) {
alert(p + _0x7b4ax13)
}
}
var bkZ = 'a5e8d2e9c1721ae0e84ad660c472c1f3',
skH = 'nhasasdbasdtene7230asb',
iv, key;
iv = CryptoJS['enc']['Hex']'parse', key = CryptoJS.SHA256(skH)

@L2501
Copy link

L2501 commented Mar 15, 2017

it same aes as used in their other sites

all you need is to get the key and iv


 var bkZ = 'a5e8d2e9c1721ae0e84ad660c472c1f3',
     skH = 'nhasasdbasdtene7230asb',
     iv, key;
 iv = CryptoJS['enc']['Hex']['parse'](bkZ), key = CryptoJS.SHA256(skH)

key = hashlib.sha256('nhasasdbasdtene7230asb').digest()
iv = 'a5e8d2e9c1721ae0e84ad660c472c1f3'.decode('hex')

crypter = AES.new(key, AES.MODE_CBC, iv)
crypter.decrypt(cypertext.decode('base-64'))

@RexfelisLOC
Copy link
Author

Awesome thanks. I was able to replace the token with the skH value and it works.

@Twoure
Copy link
Owner

Twoure commented Mar 15, 2017

Thanks for the info, I'll push a fix when I can.

@Twoure
Copy link
Owner

Twoure commented Mar 16, 2017

Fixed anime. Currently working on cartoon, then will check drama for changes.

@Twoure Twoure self-assigned this Mar 16, 2017
@Twoure Twoure added the bug label Mar 16, 2017
@Twoure Twoure added this to the v1.3.0 milestone Mar 16, 2017
@Twoure
Copy link
Owner

Twoure commented Mar 16, 2017

Finished cartoon/drama js decryption. Still need to translate into python, and make dynamic.

@RexfelisLOC
Copy link
Author

RexfelisLOC commented Mar 16, 2017

I'm curious if your library can play videos from the beta server. Here's a video which is only available using Openload or KissAnime's beta server (KissAnime server is not available):

http://kissanime.ru/Anime/Naruto-Shippuuden/Episode-003?id=100312&s=beta

Notice the &s=beta at the end. The code will extract the link, but I cannot play the link in a browser (I do not use Plex).

@Twoure
Copy link
Owner

Twoure commented Mar 16, 2017

Notice the &s=beta at the end. The code will extract the link, but I cannot play the link in a browser (I do not use Plex).

I'm seeing the same thing. I assume its a header dependency issue. Sometimes sites like these expire the video link the instant it's been called, and they normally have some dependency within the requests header. I don't have time right now to look into this any further, but will once I've patched up the channel for the default sites.

@NicholasLAranda
Copy link

Thank you for addressing this and implementing a fix.

@Twoure
Copy link
Owner

Twoure commented Mar 18, 2017

Fixed anime in 3a15779 (aka dev branch). The values are hard-coded for now, but will need to be generated later (so this patch may break in a day or two). Still looking into a good way to do this. Moving on to cartoon/drama section for now.

@Twoure
Copy link
Owner

Twoure commented Mar 19, 2017

Thanks @GreyAsteroid for bringing the manga section to my attention. I'll add this to my list of things to do. Seems the encryption is a similar style as the other sites.

@Twoure
Copy link
Owner

Twoure commented Mar 19, 2017

Fixed anime, cartoon, Asian dramas. Still working out some of the bugs, but have the ground work done. Will also take time to fix the manga section after finalizing the video sections.

@NicholasLAranda
Copy link

Any ETA when 1.3.0 releases with channel fixes? All weekend we've wants to watch some animated cartoons but since it changed, we're limited to Netflix, my small home server & the poor quality of SS-Plex & PrimeWire with their mass of dead links.

@Twoure
Copy link
Owner

Twoure commented Mar 20, 2017

@RypeDub420 said: Any ETA when 1.3.0 releases with channel fixes?

Hopefully early this week.

All weekend we've wants to watch some animated cartoons

In the meantime, tryout 9anime.bundle dev branch. If you have the ssl cert issue and can't navigate the channel, then try enabling the SSL/TLS Fix within the channel's preferences.

Please keep 9anime.bundle comments to it's support thread [REL] 9anime and issues to https://github.com/Twoure/9anime.bundle/issues.

@IJ08
Copy link

IJ08 commented Mar 20, 2017

Okay Twoure thanks for referencing. Will wait on next build. Appreciate your work in keeping your plugin up-to-date sir!

@frankr2994
Copy link

Hey just wanted to show my appreciation for your effort. Ditched cable a year back and this particular plugin has been absolutely awesome for entertaining my 4 year old. So nice to be able to hit shuffle and let the TV just play. I'm trying to become more involved with Plex and will hopefully learn how to help fix, maintain or create my own plugin. For now I am patiently waiting for your updates as they come through.

@MisterVulcan
Copy link

Ditto from the guy above me. Am willing to do python coding for free anime :-).

@Twoure
Copy link
Owner

Twoure commented Mar 21, 2017

Fixed default videos in eda694b...bbd22af available from the current dev branch. Moving on to manga section for now, then will revisit the new beta video host.

@bearsnacks
Copy link

I also wanted to show my appreciation. Thanks for doing all this!

@Prometheusx-git
Copy link

Hi Twoure,
i would like to use your Code for the Kodi Kissasian Addon.
After changing the Code to work with Kodis python, i've got a problem with the get_rks() function.
I changed it like this:

cl = list()
bl = list()
key = ""
code = ""
ra = re.findall(r'<script type="text/javascript">(.?)</script',page, re.DOTALL)
#html = HTML.ElementFromString(page)
for node in ra : #html.xpath('//script[@type="text/javascript"]'):
r = re.search(r'var\s
?(_[^\=]+)=$kissenc',node)
if r:
key = r.group(1)
cl.append('var %s = "%s"; ' %(key, rks_init))
continue
r2 = re.search(r'($kissenc[^\(]+(%s))' %key, node) if key else None
if r2:
continue
r3 = re.search(r'(%s)' %key,node) if key else None
if r3:
for i, n in enumerate(node.strip().split(';')):
n = n.strip()
if re.search(r'(%s)' %key,n):
r4 = re.search(r'\s([^\(\=]+)(',n)
if r4:
n = "function %s(a, b) {return a + 'bl_key' + b};" %r4.group(1) + n
cl.append(n.lstrip('} \n') + ';')
elif (i == 0):
r3 = re.search(r'var\s*?(_[^\=]+)=["'["']]',n)
if r3:
bl = [ b64decode(s.strip().decode('unicode_escape')) for s in r3.group(2).split(',') ]
code = ''.join(cl + [' %s' %key]) if cl else ''
code = code.replace('bl_key', (bl[0] if bl else '$'))
if code:
return js2py.eval_js(code)
return False

Unfortunatly the execution of js2py.eval_js(code) fails.
The variable "code" looks for example like this:
var _duMLg = "Agxck2w4kG82A5tho"; var t = _duMLg;function x352(a, b) {return a + '$' + b};_duMLg = x352('5', _x1);_duMLg += t;_duMLg += '10'; _duMLg

Could you see a mistake or give a hint?

@RexfelisLOC
Copy link
Author

FYI, KissCartoon is returning a "http://kisscartoon.se/Play?" for video links. Not sure if you are handling this, but if you try to play the link, KissCartoon will return "Please do not do that!"

@Twoure
Copy link
Owner

Twoure commented Mar 21, 2017

@Prometheusx-git and @RexfelisLOC, thanks for the heads up.

@Twoure
Copy link
Owner

Twoure commented Mar 22, 2017

@Prometheusx-git
The code changes per user (I'm guessing based on IP and other params). https://www.reddit.com/r/KissAnime/comments/60fbp0/the_state_of_kissanime_kodi_addons_and_how/

So it seems my code above isn't going to work for the page your getting. I've not seen the code change on my end for almost two days now. I'll have to wait and see what it changes to.

@IJ08
Copy link

IJ08 commented Apr 13, 2017

Did the comment but did not work, I get channel not responding. Attaching logs here - both Anime and Cartoons are not working.

com.plexapp.plugins.kissnetwork.zip

@Twoure
Copy link
Owner

Twoure commented Apr 13, 2017

@IJ08, thanks, I see the issue with my zip function now. It's a Windows OS thing.

@IJ08
Copy link

IJ08 commented Apr 13, 2017

okay thanks, let me know if you need any other debugging logs. Will wait on your fixes for the specific issue when you get the time. Appreciate your help

@Twoure
Copy link
Owner

Twoure commented Apr 13, 2017

@IJ08, pushed fix to dev branch.

@CastleArcade
Copy link

I've been having issues with playing anything for the past week or so, even the most recent dev branch doesn't work for me. Any suggestions on how I can fix this?

@Twoure
Copy link
Owner

Twoure commented Apr 13, 2017

@CastleArcade

@ginobean
Copy link

ginobean commented Apr 13, 2017

@Twoure , I just tried the latest dev branch, doing a cksum of ServiceCode.pys to make sure that I did indeed have the latest dev branch : (cksum ServiceCode.pys
4201737398 16202 ServiceCode.pys).
As a test, I tried playing two videos. One was KDrama Tunnel (2017), episode 5 and other was an anime, Ranma 1/2 (Sub), episode 37.

Neither of them worked. I live in New Jersey, so there shouldn't be any blocking issues.

Have you considered using a scripting browser to extract the links? Such as 'selenium + chromedriver' or dryscrape?

As an experiment, I wrote Python scripts, using both 'selenium and chromedriver' and dryscrape, to extract video links from an arbitrary episode page and was able to get it to successfully extract the video link (720p version only, since that was the only version I was interested in) for both Kissasian.com and Kissanime.ru. Retrieval times were generally in the 30-60 second range, which is not too great, but with 1 hour caching of resuts, possibly acceptable and better than no video at all.

As a further test, I inserted code into get_googlevideo_url (ServiceCode.pys) to invoke my video link extraction script, and was able to get it basically working.

Although, there were some animes where the video link required the Referer header to be set, which didn't play well with my Apple TV Plex client.

The nice thing about the scripting browser solution is that I didn't have to worry about or deal with any encryption changes since the 'selenium + chromedriver' and dryscrape basically run an actual browser (chrome and QtWebKit, respectively) so they should be able to handle encryption changes without batting an eye.

The chromedriver version of the video link extraction script is only about 10K of Python code, so it didn't take long to get a basic, simple version working..

BTW, with the chromedriver version, be sure to also use an ad blocking extension, such as adguard:

# add adguard ad blocker:
chrome_options.add_extension('/usr/local/my-site-packages/adguard-2-5-11.crx')

Otherwise, it takes forever and is generally not usable.

And between the chromedriver version and the dryscrape version, the chromedriver version is easier to write and to maintain, as it's pretty much a real browser and, when something goes awry, you can actually see visually what's going on, and this makes it easier to maintain and to fix, if something changes.

@IJ08
Copy link

IJ08 commented Apr 13, 2017

@Twoure updated my kissnetwork, still same error. Attaching logs. This is new dev branch and I tried latest update per channel and using dev tools > zip, still getting channel not responding

Logs.zip

@gilfrade
Copy link

gilfrade commented Apr 15, 2017

@ginobean Your idea is solid for your use case but has too many dependencies to be a viable solution. It would not work with everyone.

@Twoure dev from today does not work for me, i can open the video from browser directly. From the logs it seems something is a miss.

Edited: Removed snipped log text as suggested by @Twoure. Restarting PMS did not work, same error. Attached zip.
KissNetwork_cache_20170415-164704.zip

@ginobean
Copy link

As a worst case scenario, it would be fairly easy for KissNetwork to change their encryption keys on a weekly basis and also make them dependent upon the first two octets of the client's IP address, as an example. In which case, it may simply become impractical to try to keep up with their ever changing encryption keys.

@Twoure
Copy link
Owner

Twoure commented Apr 15, 2017

@gilfrade, in the future, please do not copy/paste log info into a comment. Instead attache it as a file, or host it elsewhere. This will help keep the thread clean.

Also, I can't tell much from this snippet. However, it would appear the code is old, as the error message has changed. Most likely, you've used the updater built into the channel, and it failed to restart Plex's service code. You'll have to either restart your PMS, or download and install the dev branch again, then restart PMS.

@Twoure
Copy link
Owner

Twoure commented Apr 15, 2017

@ginobean, is selenium written in pure Python? Does it depend on anything other than Python? If it builds binary packages based on OS, then I would be required to compile them for each server platform that PMS can be built on. I do not own, nor have access to those devices, as-well-as I can not guarantee selenium will work for unRAID, QNAP, Nvidia Shield, etc...

@NicholasLAranda
Copy link

http://forum.kissanime.com/index.php?threads/・「12-april-2017」concerning-kimcartoon-and-a-miscommunication.1883/

KimCartoon.me is the official replacement for KissCartoon.me.

@Twoure
Copy link
Owner

Twoure commented Apr 15, 2017

@RypeDub420, correct, and already stated in Comment_1417966.

@NicholasLAranda
Copy link

Oh snap. My RypeDub Gmail push notifications are super behind lol

How do you install the dev branch in WebTools?

@Twoure
Copy link
Owner

Twoure commented Apr 15, 2017

@RypeDub420, you can't, but you can change the channel's Update Channel to Development and wait for the update button to appear within the channel. Optionally, you can download the dev.zip and follow the directions in readme#install to update.

Note: you'll need to do step 3 in #63 (comment) for cartoon section to potentially work.

@Twoure
Copy link
Owner

Twoure commented Apr 15, 2017

@gilfrade said:
@Twoure dev from today does not work for me, i can open the video from browser directly. From the logs it seems something is a miss.

Edited: Removed snipped log text as suggested by @Twoure. Restarting PMS did not work, same error.

Thanks @gilfrade, I see the error, and fixed in c4b99b2.

@ginobean
Copy link

@Twoure , I took a look at contents of the latest selenium python package (tar tf selenium-3.3.3.tar) , and it looks like it's pure python except for the firefox webdriver which seems to have .so (dynamic libraries) in it.

Additionally, chromedriver itself is platform dependent, i.e. each platform (Linux, macOS, Windows) would have to have it's own executable chromedriver binary.

@zaphod765
Copy link

Just wanted to say thanks for all the hard work, I know this latest break has been challenging. Let me know if I can help with testing? Thank you Twoure, you rock!

@dominick1233
Copy link

so does this channel work again or...? I tried the latest dev branch manual install but still getting error.

@Twoure
Copy link
Owner

Twoure commented Apr 29, 2017

Updated dev branch for a few more variants today. Refer to #63 for more info.

@IJ08
Copy link

IJ08 commented Apr 29, 2017

@Twoure tested latest dev.

ANIME - working
Cartoons - NOT WORKING, probably due to the source it pulls it from

I don't use the "DRAMA" part so it doesn't matter, but in case you wanted to check if it works or not, well it doesn't. Attaching the logs -
log.zip

@Twoure
Copy link
Owner

Twoure commented Apr 29, 2017

@IJ08 try resetting your Domain_Dict then the Header_Dict from the channel's DevTools. And then clear the DataHTTP cache as well, to remove any pages incorrectly cached.

@IJ08
Copy link

IJ08 commented Apr 29, 2017

Still the same after following above steps, I also noticed that anime channel only plays newer animes, I tried to play an older anime but it did not work. The ones that are working are all on new updated. Logs attached.
log.zip

@Twoure
Copy link
Owner

Twoure commented Apr 29, 2017

@IJ08 I also need the corresponding com.plexapp.system.log as that's where the video stream information is logged when it's played.

@Twoure
Copy link
Owner

Twoure commented Apr 29, 2017

Fixed cartoon searching in 84f81df

@IJ08
Copy link

IJ08 commented Apr 29, 2017

@Twoure here you go -
log.zip

@Twoure
Copy link
Owner

Twoure commented Apr 29, 2017

@IJ08, looks like you may have have another variant for encryption than I've coded for. Work though #63 and upload the zip file to #63. However, make sure to test a different KimCartoon video than you have been in the past, as there may be some cache issues with their token. Also, make sure to grab the latest dev branch and restart your PMS after installing.

@IJ08
Copy link

IJ08 commented Apr 30, 2017

@Twoure I downloaded the latest dev branch from you comments. And did all the steps but the error is the same. Let me update in that forum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests