Showing posts with label Website Security. Show all posts
Showing posts with label Website Security. Show all posts

Friday, December 7, 2018

Takeaways and highlights from AWS re:Invent 2018

I had an opportunity to attend the seventh installment of AWS re:Invent. It was indeed a large gathering with more than 50,000 in attendance. Despite the size of crowds, the conference was very well run. I was not able to reserve a seat for all the workshops and sessions I was interested in advance but I was able to attend most of these workshops and sessions by queuing up in the walk-up line. Here are some of the takeaways and highlights.

Machine Learning was front and center

AWS provides ML capabilities at three levels of abstraction.
  1. Fully managed services such as AWS Rekognition, Polly, Amazon Comprehend (NLP), Alexa, etc. AWS introduced Textract, a smart OCR service.
  2. Managed execution of pre-built or custom ML models. SageMaker fills this role. 150+ machine learning algorithms are being made available in the AWS Marketplace.
  3. Infrastructure for running ML tools such as MXNet, PyTorch, TensorFlow, etc.
  • Several new sub-services for SageMaker were announced. For models that require a manual effort to train, AWS introduced SageMaker Ground Truth for classification of data via Mechanical Turk, or other sources. AWS also introduced SageMaker RL which performs training of models through rewards over time. To promote this service, AWS introduced DeepRacer, a fully autonomous 1/18th scale race car driven by reinforcement learning to help developers gain hands-on working knowledge of SageMaker RL. Amazon SageMaker Neo enables machine learning models to train once and run anywhere in the cloud and at the edge with optimal performance.
  • AWS also announced AWS Inferentia, a new inference chip (yes, a custom-built computer chip) that promises to significantly reduce the time it takes to draw inference from an ML model.
  • ML Insights works with Amazon QuickSight, a BI Service for interactive dashboards. ML Insights adds ML-powered anomaly detection, ML-powered forecasting, and Auto-narratives (add text descriptions automatically) to QuickSight dashboards.
  • AWS Personalize is managed service for building and consuming recommendations models. It does the heavy lifting needed to design, train, and deploy a machine learning model under the covers.
  • AWS RoboMaker provides a robotics development environment for application development (open-source robotics software framework, Robot Operating System,ROS), a robotics simulation service to accelerate application testing, and a robotics fleet management service for remote application deployment, update, and management.

AWS IoT services matured and can now connect to more things

  • AWS IoT Core can now ingest data directly, bypassing the MQTT broker, by having the thing publish data to $aws/rules/ruleName topic. This eliminates the additional time and cost of publishing data to an IoT topic before it reaches the rules engine for desired processing.
  • AWS IoT SiteWise opens up AWS IoT to data from industrial devices. It runs on a gateway that resides in customer's facilities and automates the process of collecting and organizing industrial equipment data.
  • AWS IoT Events - Managed service to analyze patterns in IoT data respond accordingly.
  • AWS IoT Things Graph can be used to connect devices and web services to build IoT applications. With this service, one can define interactions between them to build multi-step automation applications.

Serverless computing saw some important improvements

  • AWS Lambda now natively supports Ruby.
  • Lambda now supports custom runtimes (any runtime that can run on Unix) via Lambda Runtime API. C++ and Rust are now supported on Lambda using this new feature. Some other languages that third-parties have enabled on AWS Lambda are Erlang, Elexir, COBOL, and PHP. This feature will certainly encourage migration of legacy code to Lambda.
  • A new feature of Lambda called Layers allows lambda functions to share code and data. For example, if several Lambda functions use a common library, that library does not need to deployed (duplicated) for each these Lambda functions. Instead, the library can be pulled in from a remote repository.
  • Step function (orchestration of Lambda functions) can now invoke many AWS managed services (such as DynamoDB, AWS Batch, Amazon SQS, and Amazon SageMaker) directly in a defined flow.
  • A new service called AWS Serverless Application Repository allows cataloging/discovery/assembly of a serverless application from existing Lambda functions.
  • Lambda functions can now be placed behind an Application Load Balancer. This allows Lambda functions to be invoked directly via HTTP/HTTPS without having to use the API Gateway.
  • Firecracker is a lightweight virtualization that is based on KVM. Amazon uses this technology internally to for its AWS Lambda offering as well. According to AWS, this service allows "launching of lightweight micro-virtual machines (microVMs) in non-virtualized environments in a fraction of a second, taking advantage of the security and workload isolation provided by traditional VMs and the resource efficiency that comes along with containers".
  • AWS App Mesh - For monitoring and controlling communication across microservices on AWS such as ECS, EKS and Kubernetes running on EC2.
  • API Gateway now supports Web Sockets. For Single Page Apps, live updates from the Server are usually sent over Web Sockets. This makes API Gateway more desirable as a backend for interactive SPAs.
  • SNS now supports filtering of messages that are published to a given SNS topic. This can help discard undesirable messages at the SNS service level thus reducing traffic to a configured SNS recipient such as AWS Lambda or a microservice.

Databases and Storage

Amazon Aurora, a MySQL-based managed database service, was featured prominently in Werner's keynote. Amazon has famously vowed to get rid of all its Oracle databases. I imagine Aurora will replace a good number of these databases.
  • Amazon Aurora added a Global database feature that is designed for applications with a global footprint. It allows a single Aurora database to span multiple AWS regions, with fast replication to enable low-latency global reads and disaster recovery from region-wide outages. I imagine one of the main motivations for adding this feature was to match Microsoft Azure Cosmos Database's globally distributed storage model.
  • Amazon DynamoDB added ACID-compliant transactions across multiple tables in a given AWS region. This is important for applications that need to store data reliably across multiple tables in a single transaction. DynamoDB also added an On-demand pricing model where the application does not need upfront capacity planning (read/write capacity units).
  • Amazon Timestream is a new database offering optimized for storing timestream data and is more cost effective than other storage options such as RDS. This is an attractive option for storing large amount of streaming data such as Telemetry data from IoT devices.
  • Amazon had previously introduced AWS Glue to discover and catalog structured and unstructured data to aid in building of a Data Lake. Amazon has now introduced AWS Lake Formation, that sits on top of AWS Glue, and makes the job of configuring data sources and governance of the source data much simpler.
  • S3 added intelligent tiering which automatically moves data to different pricing/availability tiers of S3 based on S3 object access patterns.
  • AWS Transfer for SFTP is new fully managed SFTP service S3. This allows access to data stored in S3 buckets through SFTP protocol.
  • Amazon introduced Amazon FSx for Lustre, a fully managed file system for use with Lustre, a file system used for large-scale cluster computing. Similarly, Amazon FSx for Windows File Server delivers a managed Windows file system (supports SMB, NTFS and AD) for use with workloads on Windows Server.

Amazon finally gets into the Blockchain game

Two Blockchain related services were announced.
  1. Amazon Managed Blockchain is a fully managed service that makes it easy to create and manage scalable Blockchain networks using popular open source frameworks Hyperledger Fabric & Ethereum.
  2. Amazon Quantum Ledger Database (QLDB) is a purpose-built ledger database that provides a complete and verifiable history of application data changes. The database is append only/immutable (can't be edited) and cryptographically verified (to ensure contents have not been tampered).

Finally, there were new offerings in the area of DevOps and Security

  • AWS CodeDeploy now supports Blue/Green deployments for AWS Fargate and Amazon ECS.
  • AWS Security Hub enables AWS customers to centrally view and manage security alerts and automate compliance checks within and across AWS accounts.
  • AWS Control Tower helps create and maintain secure, well-architected multi-account AWS environments with respect to configuration of organizations, federated access, centralized logging, IAMs auditing, and workflows for provisioning new accounts.
  • AWS Well-Architected Tool can review state of workloads and compare them to the latest AWS architectural best practices.
  • AWS Outposts (later in 2019) - An on-premise hardware offering developed jointly by Amazon and VMWare. It is fully managed, maintained, and supported by AWS to deliver access to the latest AWS services on customer's site. It brings native AWS services, infrastructure, and operating models to virtually any data center, co-location space, or on-premises facility.
Well, that's all for this year. I believe we are nowhere near utilizing the full potential of AI, Machine Learning, and IoT data. I have no doubt we will see many more outstanding innovations in these areas in the near future. We are now well-beyond dynamic websites (Web 1.0) and mobile computing (Web 2.0). Warp speed to AI, ML and IoT (Web 3.0).

Tuesday, October 6, 2015

SSH Secure Shell

SSH

Telnet lets you control another computer remotely. SSH is a secure telnet. Telnet lets you control another computer remotely.

The computer we want to control must have "SSH Server" installed.

SSH Server

Open SSH Daemon - SSHD is the Server

- Password

- Public/Private Key Pair

- Host Based (file containing known hosts)

 Mac: System Preferences | Sharing | Remote Login

 Unix: sudo apt-get install openssh-server

               Check if it is running:       sudo systemctl status ssh

 Rap Pi: sudo raspi-config

               Interfacing Options | P2 SSH           

Windows 10: Apps & Features | Add Feature | Open SSH

services.msc | OpenSSH SSH Server | Autostart on boot

 Android: Install SimpleSSHD app

 iOS: No option available

Generate Keys

ssh-keygen

~/.ssh/id_rsa (private key)

~/.ssh/id_rsa.pub (public key, goes on the server in the following file)

"authorized_keys" folder (in .ssh/authorized_keys)

Client Computer

To connect:

ssh username@ip_address

(prompts for password if keys are not setup) 

Need to install SSH software 

Mac/Linux/RasPi: Enabled by default 

Windows 10: Apps & Features | Enable OpenSSH Client 

Can also use putty.exe (has GUI)

https://www.putty.org/ 

Android: Install app Termius

Windows

Git Bash (MinGW) provides a Linux-style terminal and includes OpenSSH.

You can download Git for Windows (including Git Bash) here: http://git-scm.com/download/win

Start bash at command-line and issue ssh commands.

ssh -i [pem file] [user]@[hostname]

Changing permission of the pem file (so that ssh allows remote connect). In bash:

chmod 600 [pem file]

References:
  • https://gist.github.com/bradtraversy/f03df587f2323b50beb4250520089a9e
  • https://www.ssh.com/academy/ssh/tunneling

Monday, April 6, 2015

ASP.Net MVC: Implementing security for ASP.NET Web API application

Traditionally we use Forms Authentication / Form Authentication Token (Web.config). Redirects to login page; not very conducive for developing a GUI-less service layer.

The following are some possible extension points for securing an ASP.NET Web API application.

Implement custom authentication/authorization logic in the following extension points. We can still use the Form Authentication Token to save the credentials in a cookie and set the thread principal.

  • Implement and register an IIS IHttpModule (Runs before message handlers, and filters).
  • Use Message Handlers run by the ApiController.ExecuteAsync. Implement and register a DelegatingHandler-derived class (Runs before Filters).
  • Use Filters such as Authorize[] (method, controller, or global scope). We can derive from AuthorizeAttribute class to implement custom logic.

Saturday, April 19, 2014

Web Dev: Big 5 Security Measures for your Web Applications

1. Use SSL

Encryption of data in transit

If your site serves up private information, use SSL.

Use SSL, not just for the login page of your website but throughout the website. Typically, authentication credentials are stored as HTTP Cookies that are transmitted with every HTTP request. It makes no sense to grant these authentication cookies securely and later transport them insecurely for all the hackers to see (by using Network sniffers). 

Use of SSL is the easiest security measure you can take. The effectiveness of the rest of the security measures described below, directly or indirectly, depend upon communicating website data over a secure communication channel.

Be sure that all security updates have been applied to your Web server. For example, if you are using OpenSSL you should close the Heartbleed Virus loophole. See: https://www.openssl.org/news/secadv_20140407.txt

2. Guard against SQL Injection Attacks

Execution of malicious SQL statements against the database

If your code forms SQL queries dynamically by directly concatenating values entered by the user, your application may be vulnerable to SQL injection attacks.

Let's say you allow users to lookup whether they are already registered on your website by entering their email address.

Behind the scenes, your code forms the following SQL query.

string sqlUserExists = "SELECT * FROM RegisteredUsers WHERE EmailAddress='" + userEnteredAddress + "'";

If the user enters, someone@xyz.com for userEnteredAddress, you get the following SQL query.

SELECT * FROM RegisteredUsers WHERE EmailAddress='someone@xyz.com';

So far, so good. But what if the user enters the following text for userEnteredAddress:

badguy@xyz.com';delete from RegisteredUsers --

The corresponding dynamic SQL becomes the following statement that deletes all users from the RegisteredUsers table.

SELECT * FROM RegisteredUsers WHERE EmailAddress='badguy@xyz.com';delete from RegisteredUsers --';

Mitigations

  1. Clean the user entered values that you use in dynamic SQL (for example, using RegEx). This is not the best way to guard against SQL injection attacks since the your code is responsible for cleaning up values everywhere in the code and will likely miss certain loopholes.
  2. Use Parameterized Queries (see SqlCommand.Parameters)
  3. Use Stored Procedures
  4. Use an ORM tool

3. Guard Against Cross Site Scripting (XSS)

A malicious script is executed from victim's browser to steal sensitive information or to cause harm to other sites using victim's browser

Modern websites use client side scripts (such as JavaScript) to enhance user experience. In an XSS attack, these scripts are manipulated to do malicious things such as alter DOM elements of the web page, send sensitive information to hacker sites, and to steal authentication credentials. There are several ways a hacker injects malicious scripts.

I. Passes malicious script as part of the query string. Many web applications directly use the contents of the query string to generate Web forms HTML and returns them as part of  Web pages. If the contents the query string contain valid (and malicious) HTML tags and scripts, they are returned back to the Browser as part of the form and executed causing a security breach. This is an example of a reflected malicious script.

II. Injects malicious scripts into the database that returns information to the user's Web browser (see SQL injection attack description above). For example, a malicious script is inserted into one of the database columns of an entity. When that entity is displayed in user's Web browser, the malicious script is executed. This is an example of a persistent malicious script.

III. Enters input values that contain malicious script which in turn is unsafely processed by our client-side scripts. For example, if our site shows an alert by echoing values entered by the user or by adding DOM elements with values obtained after parsing JSON data (with JavaScript or jQuery), we are susceptible to such attacks. Instead of entering plain text script, a hacker may enter an encoded string to further confuse our scripts.

Mitigations

  1. Clean data before processing or storing it. AntiXss Sanitizer is a library that provides such capabilities (Sanitizer.GetSafeHtml() and Sanitizer.GetSafeHtmlFragement()). Specify UTF-8 encoding in web.config. That way, the hacker cannot override the text encoding and the sanitizing rules are fully enforced.
  2. When manipulating DOM, use safe methods to set values. For example, use setAttribute to set an attribute of an element instead of directly manipulating the html() of an element.
  3. Remember, not all scripts are present in <script> tags. A script may be entered as part of an HTML tag (<img onClick="alert(input)"/>). Avoid such scripts if you can (for example, use jQuery instead to add click handlers; that way the scripts will be under <script/> tags and will be easier to audit).
  4. In ASP.NET, enable <system.web><httpRuntime  requestValidationMode="2.0" /></system.web>. This instructs ASP.NET to examine input from the browser for dangerous values.
  5. Use safe methods to output values of a variables to a Web page. For example, in MVC use @dataVar to safely output the value of a variable to a Web page. Micrsoft.Security.Application.Encoder.HtmlEncode(input) and Json.Encode(model) are also available to encode input that contains HTML/JavaScript.

4. Guard Against Cross Site Request Forgery (CSRF)

A malicious request is executed from victim's browser using victim's credentials

Hacker uses victim's authentication credentials from victim's own browser to steal information. Here's how it works.
  1. Victim visits and logs into their bank site.
  2. Without logging out, the victim knowingly or unknowingly invokes script from a malicious site (lured by an image or any link in email, or by navigating to a link on a malicious website). 
  3. Since the victim is still logged into their bank site, the malicious code (usually a script disguised as a link to image) performs inappropriate actions on victim's bank website usually by making a background AJAX call.
Note: Cross Site Scripting (XSS) can also be used to get the malicious script into the victim's browser.

Mitigations

  1. Use HTTP GET exclusively for retrieving information (i.e. no data updates should ever occur as a result of an HTTP GET). 
  2. Use HTTP POST/PUT/DELETE for updates. 
  3. For an ASP.NET Web Form, add Session.SessionID to Viewstate. Viewstate is validated by ASP.NET and is difficult to forge by the hacker.
  4. For ASP.NET MVC applications, use @Html.AntiForgeryToken() for each HTML form. Apply [ValidateAntiForgeryToken()] to the POST controller method.

5. Secure data at rest

Encrypt data that is stored in file system, and databases

Say a hacker gains access to the file system or database of your Web application. The hacker can do a lot of damage with the data stored by Web application.

Mitigations

  • Whenever possible encrypt and then store sensitive data. This puts another layer of protection between your Web application and the hacker. 
  • Always store hash of passwords (instead of plain text representation). Furthermore, use a salt when creating a hash. The use of salt will thwart against a Dictionary attack.