Sunday, April 16, 2017

(powershell) Remove line breaks from a file

I needed to remove the newlines from an exported certificate to get the public key.
Nice and simple.


 $result = 'string_with_newlines'' -replace "`t|`n|`r",""

Saturday, May 28, 2016

My GIT Notes

GIT (to practice git “try.git.io"
======================

Setup:

One time system setup:
git config —global user.name <username> 
git config —global user.email test.user@gmail.com
git config —global push.default matching (for forward compatibility, optional)
git config —global alias.co checkout (This aliases checkout to co, optional)

Note: these settings are saved globally in the "/home/<username>/.gitconfig” file


Step 1) Creating a github repository and connecting it to your project. 

NOTE: you need to create a project repository on the github website then add remote target to git.

  on the github web site: "+New Repository” enter <projectname> 

  on the local machine in the <projectname> directory
git remote add origin https://github.com/<username>/<projetname>.git
  The previous line adds the following to the "<projectname>/.git/config” file. 
  [remote "origen"]
        url = https://github.com/<username>/sample_app.git
        fetch = +refs/heads/*:refs/remotes/origen/*
  [branch "master"]
       remote = origen
        merge = refs/heads/master
 
Step 2) Initializing and synchronizing the project 

initialize git: (use this the first time for each project)

cd <project root directory>

git init  (Create an empty git repository or reinitialize a current one)

git add -A  (Adds all of the files in the current directory to a staging area {except what is in .gitignore})

git status (view files in staging area)

git commit -a -m “My log message goes here” (commit the changes to the repository {NOTE: local only})

-m “” lets you add a message to each commit. You can view the commit messages using "git log”
-a (be careful with the ‘-a’ this adds all changed files and commits them. This may or may not be what you want_ 

git add . (USE THIS VERY CAREFULLY AND NOT MUCH!!!!, This will add all data including images to your commit)

git push -u origin master (this will fail if you did not set up the github repository)


Branching
—————
git checkout -b branch-a  (This creates a new branch named “branch-a” and puts code into it)

git branch (This lists all of the current branches)
* branch-a
  master

git checkout master (Return to the master branch, Master is used for known working code. Do not post in progress code to this branch)

git diff branch-a  (This will compare the files in the master branch with the files in the “branch-a” branch and show you the difference)

To Delete a Branch
————————-
git branch -d branch-a (This will delete a branch ONLY if it has been merged, Use -D if you want to deleted regardless of merge state)



To save a work in progress if you need to go work on something else:
————————————————————————————————
git checkout -b branch-b 

git commit -am “WIP: This is a work in progress, needed to work on patch on master”

git checkout master

Tweak app

git commit -am “Fix to master done”

git checkout branch-b


To merge the branches, navigate to the branch you want code MOVED INTO and run merge:
————————————————————————————————————————

git checkout master

git merge branch-b -m “Merged branch-b features with master"


GitFlow
——————
Produces a diagram of the flow of the get matenence. 


Git Tree
———————
git tree

edit you .gitconfig and add this to the bottom
nano ~/.gitconf

tree = log —graph —decorate -oneline —all —color

Monday, May 25, 2015

(Powershell) Zip / Unzip


Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
    param([string]$zipfile, [string]$outpath)

    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

Unzip "C:\a.zip" "C:\a"

Friday, May 15, 2015

(PowerShell) Quick and dirty NetCat style listener

I was trying to come up with something in PowerShell that would listen on an arbitrary port and return a string. This seems to do the job perfectly.


while ($true)
{
    $listener = new-object System.Net.Sockets.TcpListener([System.Net.IPAddress]::Parse('0.0.0.0'), 42000)

    $listener.start()

    $client = $listener.AcceptTcpClient()

    $stream = $client.GetStream()
   
    $stWriter = new-Object System.IO.StreamWriter($stream)
   
    $stWriter.WriteLine("Put your text right here")
    $stWriter.Flush
    $stWriter.Close()

    $client.Close()

    $listener.Stop()

    write-host "Connection closed."
}

Thursday, April 30, 2015

(Metasploit) Clear console history

This is going here just so I don't have to go looking for it again.
I was trying to figure out how to clear the Metasploit command history to have a fresh msfconsole experience. It turns out that it is stored in the /root/.msf4/history file.

So we check the file sizes of the history and log files using tree -ha
















and clear them out.

echo "" > /root/.msf4/history

Done

Tuesday, April 28, 2015

(ASA5512) No ASDM connection

Thanks for this one Cisco :(

The symptoms of this particular problem threw me a little because ssh worked fine but ASDM just showed "Page not Found" or some such crap. Now I wanted to do some clean up on this box any way so I

erase disk0:/
format disk0:/

re-uploaded the core files.

asa912-smp-k8.bin
asdm-713.bin
csd_3.5.2008-k9.pkg
anyconnect-win-2.5.2014-k9.pkg

When it came back up I entered the license key and it still did not work >:(

So anyway, here is the fix.

Add these two lines in config# mode:
ssl encryption aes128-sha1 
ssl encryption 3des-sha1


The issue is described in the ASDM manual:




Monday, April 20, 2015