Understanding QR Code Phishing (QRishing)

am
IT Security In Plain English
7 min readJun 22, 2024
source: Google

QR codes, or Quick Response codes, have become ubiquitous in our daily lives, providing a convenient way to access information, websites, and services with just a quick scan. However, this convenience also brings security risks, one of which is QR code phishing, commonly referred to as “QRishing.” This article delves into the concept of QRishing, explores case studies, provides examples, methods, and preventive measures, and even includes some code snippets to understand the technical aspects better.

What is QRishing?

QRishing is a type of phishing attack that uses QR codes to direct victims to malicious websites or applications. The attacker typically replaces legitimate QR codes with their own, leading users to phishing sites designed to steal sensitive information such as login credentials, financial information, or personal data.

How QRishing Works

  1. Creation of Malicious QR Codes: Attackers create QR codes that link to phishing websites or trigger malicious actions.
  2. Placement of QR Codes: These QR codes are then placed in public places, sent via emails, or embedded in seemingly legitimate documents.
  3. Scanning by Victims: Unsuspecting users scan the QR codes with their smartphones, believing they are accessing legitimate content.
  4. Execution of Attack: The scanned QR code redirects the user to a phishing website or initiates the download of malicious software, leading to data theft or device compromise.

Detailed Examples and Case Studies

Example 1: Fake Restaurant Menus

Attackers replaced legitimate QR codes on restaurant menus with malicious ones. When customers scanned these codes to view the menu or make payments, they were redirected to a phishing site designed to steal their payment information. This case emphasizes the need for vigilance in public places where QR codes are frequently used.

Impact and Response: The restaurant’s reputation suffered as customers became wary of using the establishment’s services. The incident prompted the restaurant to implement stringent security measures, including regularly checking and replacing QR codes and educating staff and customers about the risks.

Example 2: Event Registration Scam

During a major conference, attackers distributed flyers with QR codes promising exclusive access to event materials. Scanning the QR code led attendees to a fake registration site that collected personal information and payment details. This example highlights the importance of verifying the source of QR codes in event settings.

Impact and Response: Many attendees fell victim to the scam, resulting in identity theft and financial losses. The conference organizers responded by issuing a public warning, enhancing their security protocols, and collaborating with cybersecurity experts to prevent future incidents.

Example 3: Utility Bill Fraud

Attackers sent out utility bill statements with QR codes for quick payment. These codes directed users to a phishing site that mimicked the utility company’s payment portal, resulting in stolen payment information. This case underlines the risk of QR codes in financial transactions and the need for secure communication channels.

Impact and Response: The utility company faced numerous complaints from customers, leading to a loss of trust. They introduced secure payment methods, including encrypted QR codes, and launched an awareness campaign to educate customers about recognizing legitimate communications.

Attack Methods

  1. Physical Replacement: Attackers physically replace legitimate QR codes in public places with malicious ones. This method is common in high-traffic areas such as cafes, stores, and public transportation.
  2. Digital Distribution: Malicious QR codes are sent via email, social media, or messaging apps, often disguised as links to important documents, event details, or promotional offers.
  3. Website Embedding: Attackers embed malicious QR codes on compromised websites or in downloadable materials, leading to phishing sites or initiating malware downloads.
  4. Social Engineering: Attackers use social engineering tactics to trick users into scanning malicious QR codes by impersonating trusted entities or creating a sense of urgency.

Prevention Techniques

  1. Educate Users: Raise awareness about the risks of QRishing and encourage users to be cautious when scanning QR codes.
  2. Verify Sources: Always verify the source of a QR code before scanning. Use QR code scanning apps that provide a preview of the URL before opening it.
  3. Use Secure QR Code Generators: Ensure that QR codes are generated and managed securely. Regularly audit and update public QR codes.
  4. Monitor and Report: Implement monitoring systems to detect unauthorized changes to QR codes in public places. Encourage users to report suspicious QR codes.

Technical Insights and Code Snippets

Understanding how QRishing works at a technical level can help in developing better security measures. Below is an example of how a QR code can be generated and read using Python, along with measures to validate its source.

Generating a QR Code with Enhanced Security

Using the qrcode library in Python, you can generate a QR code and add validation mechanisms.

import qrcode
from hashlib import sha256

# Data to be encoded
data = "https://secure-website.com"
# Generate a hash for validation
data_hash = sha256(data.encode()).hexdigest()
# Create QR Code instance with embedded hash
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(f"{data}|{data_hash}")
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image(fill_color="black", back_color="white")
# Save the image
img.save("secure_qr_code_with_hash.png")
import cv2
from pyzbar.pyzbar import decode
from hashlib import sha256
import requests

def validate_qr_code(image_path):
# Read the image
img = cv2.imread(image_path)
# Decode the QR code
decoded_objects = decode(img)
for obj in decoded_objects:
qr_data = obj.data.decode("utf-8")
data, data_hash = qr_data.split("|")
# Validate the hash
if sha256(data.encode()).hexdigest() == data_hash:
print(f"Valid QR code. URL: {data}")
response = requests.get(data)
if response.status_code == 200:
print("The URL is valid and reachable.")
else:
print("Warning: The URL is not reachable or may be malicious.")
else:
print("Warning: The QR code is invalid or has been tampered with.")
# Example usage
validate_qr_code("secure_qr_code_with_hash.png")he QR code
decoded_objects = decode(img)
for obj in decoded_objects:
qr_data = obj.data.decode("utf-8")
data, data_hash = qr_data.split("|")
# Validate the hash
if sha256(data.encode()).hexdigest() == data_hash:
print(f"Valid QR code. URL: {data}")
response = requests.get(data)
if response.status_code == 200:
print("The URL is valid and reachable.")
else:
print("Warning: The URL is not reachable or may be malicious.")
else:
print("Warning: The QR code is invalid or has been tampered with.")
# Example usage
validate_qr_code("secure_qr_code_with_hash.png")

Advanced Attack Methods

  1. QR Code Cloaking: Attackers use URL shorteners or redirects to disguise the final destination of the QR code, making it harder for users to identify malicious links.
  2. Dynamic QR Codes: Attackers create dynamic QR codes that can change their destination after being scanned, making it challenging to detect and prevent malicious activity.
  3. Multi-Stage Attacks: QRishing can be part of a multi-stage attack where the initial scan leads to a legitimate-looking site that then prompts users to scan another QR code or download malicious software.

Technical Insight: Cloaking Techniques

URL Shortening Example:

Attackers often use URL shorteners to mask the actual destination URL of a QR code. This makes it difficult for users to recognize a potentially malicious link.

import pyshorteners

# Original URL
url = "https://malicious-website.com/phishing-page"
# Shorten the URL
shortener = pyshorteners.Shortener()
shortened_url = shortener.tinyurl.short(url)
# Generate QR Code for the shortened URL
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(shortened_url)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image(fill_color="black", back_color="white")
# Save the image
img.save("shortened_url_qr_code.png")

Technical Insight: Dynamic QR Codes

Dynamic QR Code Example:

Dynamic QR codes can change their destination after being scanned. This can be used for legitimate purposes, such as updating marketing information, but can also be exploited by attackers.

import qrcode
# Data for the dynamic URL (example using a redirection service)
data = "https://dynamic-qr-service.com/update?id=12345"
# Create QR Code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image(fill_color="black", back_color="white")
# Save the image
img.save("dynamic_qr_code.png")

Detection and Prevention of QRishing

Detection Tools:

Implementing tools to detect and prevent QRishing is crucial. One such tool is a browser extension that warns users about potentially malicious QR codes.

// Example of a browser extension to detect malicious URLs
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
let url = new URL(details.url);
if (isMalicious(url)) {
return { cancel: true };
}
},
{ urls: ["<all_urls>"] },
["blocking"]
);

function isMalicious(url) {
// Check against a list of known malicious domains
let maliciousDomains = ["malicious-website.com", "phishing-site.com"];
return maliciousDomains.includes(url.hostname);
}

QR Code Verification:

Verification processes should be integrated into applications that utilize QR codes, ensuring that only legitimate codes are accepted.

def verify_qr_code(qr_data):
# Example verification function
known_hashes = {
"https://secure-website.com": "d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2"
}
data, data_hash = qr_data.split("|")
if known_hashes.get(data) == data_hash:
print("QR code is verified.")
else:
print("QR code verification failed.")

Future Trends in Qrishing:

As technology evolves, so do the tactics of cybercriminals. Future trends in QRishing may include:

  1. AI-Driven Attacks: Attackers using AI to create more convincing phishing sites and to adapt QR codes dynamically based on user behavior.
  2. IoT Integration: Increased use of QR codes in IoT devices, presenting new opportunities for QRishing.
  3. Augmented Reality (AR) Exploits: QR codes integrated into AR experiences, leading users to malicious content within virtual environments.

QRishing is a growing threat in the digital world, leveraging the convenience of QR codes to execute phishing attacks. By understanding the methods used by attackers and implementing robust preventive measures, individuals and organizations can protect themselves from falling victim to such scams. Education, verification, and the use of secure technologies are key to mitigating the risks associated with QRishing. Continuous education, verification, and the use of secure technologies are essential in mitigating the risks associated with QRishing. By staying informed and vigilant, we can harness the benefits of QR codes while safeguarding against their potential dangers.

--

--

am
IT Security In Plain English

Unapologetically Nerdy. Privacy | Encryption | Digital Rights | FOSS | Video Tech | Security | GNU/Linux. Check out https://git.aloke.tech