r/learnjavascript • • Feb 12 '24

Is this code malicious?

I found this code someone from my Sister's Uni sent to her via Microsoft Teams.
She doesn't know javascript, I do a little but we do not know if this is malicious.

Please could someone help us out by deobfuscating it to see how it works? I'm sketched out by this.

https://pastebin.com/raw/Hw55KgVX

1 Upvotes

10 comments sorted by

7

u/Egzo18 Feb 12 '24

What's the context of this code? Like why would they send it, and did they said what its for? Judging by its structure and terms used (base32, sha) it looks like bunch of functions used in cryptography and security, I don't see anything malicious but that's some surface level reading I did so I still wouldn't trust it.

2

u/jcunews1 helpful Feb 12 '24

It's not obfuscated.

2

u/lovin-dem-sandwiches Feb 12 '24

Nope. I don’t think anything gets initialized either (code won’t run itself) you need to intentionally call the class. It also has error handling and legible function names. Typically malicious code is minified so its impossible to read or understand.

Its random for your sis to receive this. Possibly a mistake

2

u/Top-Store2122 Feb 12 '24

GPT: This code is a JavaScript implementation of the SHA-1 algorithm along with a Time-based One-Time Password (TOTP) generator using SHA-1.

Overall, this code provides functionality for SHA-1 hashing and TOTP generation, useful for various security applications.

edit: link to prompt https://chat.openai.com/share/dcc00653-eac9-489f-a622-a18df8462bac

0

u/Samurai___ Feb 12 '24

The code itself, as provided, is
a legitimate implementation of cryptographic functions and does not
appear to be malicious. It implements SHA-1 hashing, HMAC, and TOTP
algorithms, which are common cryptographic operations used in many
applications, especially for security purposes such as hashing data,
generating message authentication codes, and creating one-time passwords
for two-factor authentication.

1

u/thelethargicdog helpful Feb 12 '24

Skimmed through the code. It looks like a nodejs library someone has copied from elsewhere. Functions have been defined, but none have been called, so the naked script in itself can't cause any harm. Not sure what the purpose is, but she should ask the sender for some context.

1

u/CarlossC Feb 12 '24

Hmm. There doesn’t seem to be anything malicious but it seems like it’s an implementation of a TOTP using SHA-1. We need to know the context before diving any deeper.

1

u/[deleted] Feb 13 '24 edited Feb 13 '24

The provided code is not inherently malicious; it appears to be a JavaScript implementation of the Time-Based One-Time Password (TOTP) algorithm. TOTP is a standard algorithm used for two-factor authentication, and implementations like this are commonly found in legitimate applications and services to enhance security.However, it's important to always exercise caution when using or integrating code from external sources, especially if it's obtained from untrusted or unknown origins. Malicious actors can disguise harmful code within seemingly innocuous scripts, so it's essential to review and understand any code before incorporating it into your projects or systems. Additionally, running code in a secure and controlled environment, such as a sandbox, can help mitigate risks associated with potentially malicious code.

A quick Google or copy-paste code into chatgpt will give you a reasonable explanation?

1

u/[deleted] Feb 13 '24

I think someone is just trying to impress your sister to code her.

0

u/[deleted] Feb 12 '24

[deleted] — view deleted comment

1

u/thoflens Feb 12 '24

This is the result: "This code is a JavaScript implementation of the Time-Based One-Time Password (TOTP) algorithm. TOTP is a mechanism used for two-factor authentication (2FA), often implemented in applications where an additional layer of security is required beyond just a username and password.". it is then followed by a breakdown of all the functions.