Monday, July 7, 2025

Create a cert from certreq

 1. Create a .inf file for your cert req


[Version]

Signature="$Windows NT$"


[NewRequest]

;Change to your,country code, company name and common name

Subject = "C=JP, O=SOME Logistics Co. Ltd., L=Shinagawa-Ku, S=Tokyo, CN=something.example.com"



KeySpec = 1

KeyLength = 4096

Exportable = TRUE

MachineKeySet = TRUE

SMIME = False

PrivateKeyArchive = FALSE

UserProtected = FALSE

UseExistingKeySet = FALSE

ProviderName = "Microsoft RSA SChannel Cryptographic Provider"

ProviderType = 12

RequestType = PKCS10

KeyUsage = 0xa0


[EnhancedKeyUsageExtension]

OID=1.3.6.1.5.5.7.3.1 ; this is for Server Authentication / Token Signing

OID=1.3.6.1.5.5.7.3.2




MachineKeySet - TRUE means it will be stored in Machine "Certificate Enrolment Requests" folder.


2. Request it:

certreq -new .\request_scapp_test.inf .\request_scapp_test.csr

3. Check it

openssl req -in .\request_scapp_test.csr -noout -text | clip


Saturday, April 26, 2025

security scanner - draft

 1. https://greenbone.github.io/docs/latest/22.4/container/index.html

2, Nessus essentials: https://medium.com/@harrmahar/installing-tenable-nessus-essentials-free-in-30-minutes-using-docker-aa668a1620a0

testing against an vulnerable app: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/


DevSevOps guidelines: https://owasp.org/www-project-devsecops-guideline/latest/



git config

 settings in git:




system specific configs are not very often in use. Those are useful if some binary that git is dependent is missing.


Global config is for most of your preferences 

local config - for one-off special case changes.


Reading: git config --global user.name

Setting: git config --global user.name "User Name"


settings written to ~/.gitconfig


List all configs: git config --list

verbose: git config --list --show-origin

more verbose: git config --list --show-origin --show-scope


Unset: git config --local --unset user.name 


.gitattributes

*.js text

*.ps1 eol=crlf

*.sh eol=lf


Filters in fit allow you to securely store secret data in git when pushing and restore it when data is pulled.






Wednesday, April 23, 2025

security headers

 HTTP Strict Transport Security (HSTS) -   web browsers are instructed to exclusively connect to a website over HTTPS - prevent from ManInTheMiddle


Syntax of HSTS:

To implement HSTS, the header is added to the website's HTTP response, specifying the maximum age, includeSubDomains directive, and preload directive, if applicable. The syntax typically follows this structure:

Strict-Transport-Security: max-age=<expire-time>; includeSubDomains; preload

max-age: Defines the duration for which the browser should cache the HSTS policy.

includeSubDomains: Optional directive that extends HSTS protection to all subdomains of the main domain.

preload: Optional directive that allows websites to be included in the HSTS preload list maintained by browsers for added security.


Example terraform code:

rewrite_rule {
name = local.rewrite_rule_name_hsts
rule_sequence = 20

response_header_configuration {
header_name = "Strict-Transport-Security"
header_value = "max-age=2592000; includeSubDomains"
}
}


The Content Security Policy (CSP)  - Content Security Policy header is by far the most powerful security header, offering unmatched protection against a several security threats.


Protects from cross side scripting. 


Syntax

Here is an example of the syntax for setting up the most basic and minimal CSP header:

Content-Security-Policy: default-src 'self';

This example sets a basic content security policy that allows only resources from the same origin ('self') to be loaded by default. Generally people do not implement it this way, usually they include multiple resources.

Additional directives can be included to define specific settings for different resource types, such as scripts, stylesheets, images, fonts, and media. Here is an example with multiple directives:

Content-Security-Policy: default-src 'self'; script-src 'self' https://example.com; style-src 'self' https://cdn.example.com;

In this example:

  • default-src 'self'; sets the default policy to allow resources from the same origin.
  • script-src 'self' https://example.com; allows scripts to be loaded from the same origin and from the 'https://example.com' domain.
  • style-src 'self' https://cdn.example.com; permits stylesheets from the same origin and from the 'https://cdn.example.com' domain.

Start with:
* script-src - defines where can we load scripts from
* form-action - defines where form can send data
* conned-src - defines where javascript can connect to and send data


Security headers do not conflict.
There is not significant performance hit.
You need to update CSP (Content Security Policy) if new scripts are being added.

Permissions Policy Header - this is least privilege in web browser. We are allowing access to device permissions that app needs.

example:

accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=(), interest-cohort=()

asd

RP - Referrer Policy - This is a privacy focused header that ensures you do not send which page your user was on to the next site they visit. 

Example: 
#https://scotthelme.co.uk/a-new-security-header-referrer-policy/

response_header_configuration {
header_name = "Referrer-Policy"
header_value = "strict-origin-when-cross-origin"
}
  1.  X Frame Options* (for backwards compatibility only, assuming you must support older browsers) - blocks framing of your site
example:

response_header_configuration {
header_name = "X-Frame-Options"
header_value = "SAMEORIGIN"
}
sd 




Wednesday, March 26, 2025

docker + snyk

 1. Installation od snyk


sudo apt update && sudo apt install nodejs npm

Verify: 

node -v

npm -v

Install 

  npm install snyk -g

 sudo npm install snyk -g

Test

 snyk --version

   docker image ls

   snyk container test ui:v1.0 --file=/path/Dockerfile



Docker install:

sudo apt-get update

sudo apt-get install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

echo   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \

$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo docker run hello-world

Add a regular user to docker group

sudo usermod -aG docker $USER

Wednesday, March 19, 2025

Thanks to Andrey Karpathy:

Basically there are some no-brainer decisions you can make in your life to dramatically improve the privacy and security of your computing and this post goes over some of them. Blog post link in the reply, but copy pasting below too.


Every now and then I get reminded about the vast fraud apparatus of the internet, re-invigorating my pursuit of basic digital hygiene around privacy/security of day to day computing. The sketchiness starts with major tech companies who are incentivized to build comprehensive profiles of you, to monetize it directly for advertising, or sell it off to professional data broker companies who further enrich, de-anonymize, cross-reference and resell it further. Inevitable and regular data breaches eventually runoff and collect your information into dark web archives, feeding into a whole underground spammer / scammer industry of hacks, phishing, ransomware, credit card fraud, identity theft, etc. This guide is a collection of the most basic digital hygiene tips, starting with the most basic to a bit more niche.


Password manager. Your passwords are your "first factor", i.e. "something you know". Do not be a noob and mint new, unique, hard passwords for every website or service that you sign up with. Combine this with a browser extension to create and Autofill them super fast. For example, I use and like 1Password. This prevents your passwords from 1) being easy to guess or crack, and 2) leaking one single time, and opening doors to many other services. In return, we now have a central location for all your 1st factors (passwords), so we must make sure to secure it thoroughly, which brings us to...


Hardware security key. The most critical services in your life (e.g. Google, or 1Password) must be additionally secured with a "2nd factor", i.e. "something you have". An attacker would have to be in possession of both factors to gain access to these services. The most common 2nd factor implemented by many services is a phone number, the idea being that you get a text message with a pin code to enter in addition to your password. Clearly, this is much better than having no 2nd factor at all, but the use of a phone number is known to be extremely insecure due to the SIM swap attack. Basically, it turns out to be surprisingly easy for an attacker to call your phone company, pretend they are you, and get them to switch your phone number over to a new phone that they control. I know this sounds totally crazy but it is true, and I have many friends who are victims of this attack. Therefore, purchase and set up hardware security keys - the industrial strength protection standard. In particular, I like and use YubiKey. These devices generate and store a private key on the device secure element itself, so the private key is never materialized on a suspiciously general purpose computing device like your laptop. Once you set these up, an attacker will not only need to know your password, but have physical possession of your security key to log in to a service. Your risk of getting pwned has just decreased by about 1000X. Purchase and set up 2-3 keys and store them in different physical locations to prevent lockout should you physically lose one of the keys. The security keys support a few authentication methods. Look for "U2F" in the 2nd factor settings of your service as the strongest protection. E.g. Google and 1Password support it. Fallback on "TOTP" if you have to, and note that your YubiKeys can store TOTP private keys, so you can use the YubiKey Authenticator app to access them easily through NFC by touching your key to the phone to get your pin when logging in. This is significantly better than storing TOTP private keys on other (software) authenticator apps, because again you should not trust general purpose computing devices. It is beyond the scope of this post to go into full detail, but basically I strongly recommend the use of 2-3 YubiKeys to dramatically strengthen your digital security.


Biometrics. Biometrics are the third common authentication factor ("something you are"). E.g. if you're on iOS I recommend setting up FaceID basically everywhere, e.g. to access the 1Password app and such.


Security questions. Dinosaur businesses are obsessed with the idea of security questions like "what is your mother's maidan name?", and force you to set them up from time to time. Clearly, these are in the category of "something you know" so they are basically passwords, but conveniently for scammers, they are easy to research out on the open internet and you should refuse any prompts to participate in this ridiculous "security" exercise. Instead, treat security questions like passwords, generate random answers to random questions, and store them in your 1Password along with your passwords.


Disk encryption. Always ensure that your computers use disk encryption. For example, on Macs this total no-brainer feature is called "File Vault". This feature ensures that if your computer gets stolen, an attacker won't be able to get the hard disk and go to town on all your data.


Internet of Things. More like @internetofshit. Whenever possible, avoid "smart" devices, which are essentially incredibly insecure, internet-connected computers that gather tons of data, get hacked all the time, and that people willingly place into their homes. These things have microphones, and they routinely send data back to the mothership for analytics and to "improve customer experience" lol ok. As an example, in my younger and naive years I once purchased a CO2 monitor from China that demanded to know everything about me and my precise physical location before it would tell me the amount of CO2 in my room. These devices are a huge and very common attack surface on your privacy and security and should be avoided.


Messaging. I recommend Signal instead of text messages because it end-to-end encrypts all your communications. In addition, it does not store metadata like many other apps do (e.g. iMessage, WhatsApp). Turn on disappearing messages (e.g. 90 days default is good). In my experience they are an information vulnerability with no significant upside.


Browser. I recommend Brave browser, which is a privacy-first browser based on Chromium. That means that basically all Chrome extensions work out of the box and the browser feels like Chrome, but without Google having front row seats to your entire digital life.


Search engine. I recommend Brave search, which you can set up as your default in the browser settings. Brave Search is a privacy-first search engine with its own index, unlike e.g. Duck Duck Go which basically a nice skin for Bing, and is forced into weird partnerships with Microsoft that compromise user privacy. As with all services on this list, I pay $3/mo for Brave Premium because I prefer to be the customer, not the product in my digital life. I find that empirically, about 95% of my search engine queries are super simple website lookups, with the search engine basically acting as a tiny DNS. And if you're not finding what you're looking for, fallback to Google by just prepending "!g" to your search query, which will redirect it to Google.


Credit cards. Mint new, unique credit cards per merchant. There is no need to use one credit card on many services. This allows them to "link up" your purchasing across different services, and additionally it opens you up to credit card fraud because the services might leak your credit card number. I like and use privacy dot com to mint new credit cards for every single transaction or merchant. You get a nice interface for all your spending and notifications for each swipe. You can also set limits on each credit card (e.g. $50/month etc.), which dramatically decreases the risk of being charged more than you expect. Additionally, with a privacy dot com card you get to enter totally random information for your name and address when filling out billing information. This is huge, because there is simply no need and totally crazy that random internet merchants should be given your physical address. Which brings me to...


Address. There is no need to give out your physical address to the majority of random services and merchants on the internet. Use a virtual mail service. I currently use Earth Class Mail but tbh I'm a bit embarrassed by that and I'm looking to switch to Virtual Post Mail due to its much strong commitments to privacy, security, and its ownership structure and reputation. In any case, you get an address you can give out, they receive your mail, they scan it and digitize it, they have an app for you to quickly see it, and you can decide what to do with it (e.g. shred, forward, etc.). Not only do you gain security and privacy but also quite a bit of convenience.


Email. I still use gmail just due to sheer convenience, but I've started to partially use Proton Mail as well. And while we're on email, a few more thoughts. Never click on any link inside any email you receive. Email addresses are extremely easy to spoof and you can never be guaranteed that the email you got is a phishing email from a scammer. Instead, I manually navigate to any service of interest and log in from there. In addition, disable image loading by default in your email's settings. If you get an email that requires you to see images, you can click on "show images" to see them and it's not a big deal at all. This is important because many services use embedded images to track you - they hide information inside the image URL you get, so when your email client loads the image, they can see that you opened the email. There's just no need for that. Additionally, confusing images are one way scammers hide information to avoid being filtered by email servers as scam / spam.


VPN. If you wish to hide your IP/location to services, you can do so via VPN indirection. I recommend Mullvad VPN. I keep VPN off by default, but enable it selectively when I'm dealing with services I trust less and want more protection from.


DNS-based blocker. You can block ads by blocking entire domains at the DNS level. I like and use NextDNS, which blocks all kinds of ads and trackers. For more advanced users who like to tinker, pi-hole is the physical alternative.


Network monitor. I like and use The Little Snitch, which I have installed and running on my MacBook. This lets you see which apps are communicating, how much data and when, so you can keep track of what apps on your computer "call home" and how often. Any app that communicates too much is sus, and should potentially be uninstalled if you don't expect the traffic.


I just want to live a secure digital life and establish harmonious relationships with products and services that leak only the necessary information. And I wish to pay for the software I use so that incentives are aligned and so that I am the customer. This is not trivial, but it is possible to approach with some determination and discipline.


Finally, what's not on the list. I mostly still use Gmail + Gsuite because it's just too convenient and pervasive. I also use 𝕏 instead of something exotic (e.g. Mastodon), trading off sovereignty for convenience. I don't use a VoIP burner phone service (e.g. MySudo) but I am interested in it. I don't really mint new/unique email addresses but I want to. The journey continues. Let me know if there are other digital hygiene tips and tricks that should be on this list.


Link to blog post version in the reply, on my brand new Bear ʕ•ᴥ•ʔ blog cute 👇


 Image

Monday, March 17, 2025

Deep Dive into LLMs

based on https://www.youtube.com/watch?v=7xTGNNLPyMI&t=227s 


1. Step is pretraining:

Ref: https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1


2. Tokenization: 

https://tiktokenizer.vercel.app/

cl100k_base is used by chatgpt


3. Neural network training.

you get a string of tokens that is 15 trilion in lenght. The training process is taking a random (zero to 8000) tokens 




Neural network returns the probablity of what token comes next. Initially (when network is not trained, those probabilities are random).



Neural network internals



https://bbycroft.net/llm


what is important is that there are number of parameters (hundrs of thousands) that developer of a model must adjust and to transform inputs into outputs. We need to find a good settings of those parameters to that preditions match up with the patters seen in training.

4. Inference. TO generate new data from the model. Goal: to see what petterns it has internalized in the paramters of its network.




5, Trainig of model. 

Example of GPT-2 (Generatively Pre-trained transformer).


https://github.com/karpathy/llm.c/discussions/677

Try training your mode: https://lambdalabs.com/

terraform provider: https://registry.terraform.io/providers/elct9620/lambdalabs/latest/docs


Base model is the one that comes out from first iteration of training. This is an internet text token simulator. This is NOT useful yet. We need an assistant. Those models are not being released by companies that train models routinely. However some have been relased.

Example: https://openai.com/index/gpt-2-1-5b-release/

what does it look like to release:
1. a python code (usually) that describes the sequence of operations in details that they make in the model: https://github.com/openai/gpt-2/blob/master/src/model.py
2. A set of parameters, this is where the values comes. for GPT-2 there was 1.6 billion paramters.

Here you can play with base models: https://app.hyperbolic.xyz/models/llama31-405b-base

when testing differnet string like 'what is 2+2?" you get different ansers, because the model is stochastic.

Model are good with memorization. if you paste a sentence from Wikipedia, it will complete it filling data from Wikipedia article. This not desirable. this is called regurgutation.

hallucination - a process where model tries to predict data, but it was not really trained and do not have this information.

in-context learning ability is a process of building structured prompts that model can learn from (for example providing a key-value pair to a model and it will continue this way).







Thursday, February 20, 2025

logging to ACR without docker client

 TOKEN=$(az acr login --name  ACR_NAME --expose-token --output tsv --query accessToken)

docker login ACR_NAME  --username 00000000-0000-0000-0000-000000000000 --password-stdin <<< $TOKEN

mail sending using app registration and MSGraph

Create an App registrion with permissions:





$TenantId = "XXXXXXXXXXXXXXX"

$ClientId = "XXXXXXXXXXXXXXXXX" $ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX" $Body = @{ grant_type = "client_credentials" client_id = $ClientId client_secret = $ClientSecret scope = "https://graph.microsoft.com/.default" } $TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token" ` -Method POST ` -ContentType "application/x-www-form-urlencoded" ` -Body $Body $AccessToken = $TokenResponse.access_token # Write-Output $AccessToken # Variables $Recipient = "john@gmail.com" # Replace with the recipient's email address $Subject = "Test Email from PowerShell" $Body = @{ Message = @{ Subject = $Subject Body = @{ ContentType = "Text" Content = "This is a test email sent using Microsoft Graph API and PowerShell." } ToRecipients = @(@{ EmailAddress = @{ Address = $Recipient } }) } SaveToSentItems = "true" } # Convert body to JSON $BodyJson = $Body | ConvertTo-Json -Depth 10 -Compress # Define headers for the API request $Headers = @{ "Authorization" = "Bearer $AccessToken" "Content-Type" = "application/json" } $Response = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/no-reply@source.domain.com/sendMail" ` -Headers $Headers ` -Method POST ` -Body $BodyJson Write-Output "Email sent successfully!"