Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
AWS lambda with selenium & python is powerful solution. Let's access this benefit easily!
# Write the method to a file. (NOT interactive mode.)
def get_title(self, url):
self.get(url)
return self.title
# Attach the method and then call it.
from chromeless import Chromeless
chrome = Chromeless()
chrome.attach(get_title)
print(chrome.get_title("https://google.com")) # Returns Google
You can also provide boto3 session object if you don't want to use default aws profile:
from chromeless import Chromeless
from boto3.session import Session
session = Session(aws_access_key_id='<YOUR ACCESS KEY ID>',
aws_secret_access_key='<YOUR SECRET KEY>',
region_name='<REGION NAME>')
# or
session = Session(profile_name='<YOUR_PROFILE_NAME>')
chrome = Chromeless(boto3_session=session)
Or also you can just set appropriate environment vars works with boto3, so it will auto detect your choice e.g.:
# In mac or linux
export AWS_DEFAULT_REGION=<your aws region>
# In windows
set AWS_DEFAULT_REGION=<your aws region>
git clone --depth 1 https://github.com/umihico/pythonista-chromeless.git chromeless && cd $_
sls deploy --region YOUR_REGION
pip install chromeless
That's it! Now run the example.py
and confirm your selenium works in lambda functions!
# BAD EXAMPLE
chrome = Chromeless()
chrome.get("https://google.com") # Not a attached method. AttributeError will be raised.
chrome.title # Same. AttributeError.
# SOLUTION
def wrapper(self, url):
self.get(url)
return self.title
chrome = Chromeless()
chrome.attach(wrapper)
print(chrome.wrapper("https://google.com")) # prints 'Google'.
print(chrome.wrapper("https://microsoft.com")) # But you can execute as many times as you want.
print(chrome.wrapper("https://apple.com")) # Arguments are adjustable each time.
def login(self):
self.get("https://example.com/login")
self.find_element_by_id("username").send_keys("umihico")
self.find_element_by_id("password").send_keys("password")
self.find_element_by_name("submit").click()
def test1(self):
self.login()
self.get("https://example.com/")
def test2(self):
self.login()
self.get("https://example.com/logout")
chrome = Chromeless()
chrome.attach(login) # You can attach multiple methods too.
chrome.attach(test1) # It means you can also refactor the common code.
chrome.attach(test2)
print(chrome.test1())
print(chrome.test2())
# BAD EXAMPLE
def bad_wrapper(self):
self.get("https://google.com")
self.save_screenshot("screenshot.png")
# There's no sense in saving files in AWS Lambda.
# SOLUTION
def good_wrapper(self):
self.get("https://google.com")
return self.get_screenshot_as_png()
# return image in binary format.
chrome = Chromeless()
chrome.attach(good_wrapper)
png = chrome.good_wrapper()
# then write then image down locally.
with open("screenshot.png", 'wb') as f:
f.write(png)
The project is licensed under the MIT license.
FAQs
Serverless selenium which dynamically execute any given code.
We found that chromeless demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.