├── .gitignore ├── .images ├── cdls.PNG ├── github banner.png └── logo.png ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── SWSH.sln ├── SWSH ├── App.config ├── ExternalFunctions.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── ReadLine.cs ├── SWSH.csproj ├── Url.cs ├── icon.ico └── packages.config ├── appveyor.yml └── checksum /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | SWSH/icon/icon.png 290 | SWSH/icon/icon.psd 291 | SWSH/icon/icon.ico 292 | swsh-keygen/swsh-keygen.exe 293 | .swsh_history 294 | *.patch 295 | swsh-data/ 296 | Installer/Installer.vdproj 297 | Installer/logo.ico 298 | -------------------------------------------------------------------------------- /.images/cdls.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecureWindowsShell/SWSH/0624a953ed867ae658abe9a298e5bf3e4d61c65d/.images/cdls.PNG -------------------------------------------------------------------------------- /.images/github banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecureWindowsShell/SWSH/0624a953ed867ae658abe9a298e5bf3e4d61c65d/.images/github banner.png -------------------------------------------------------------------------------- /.images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecureWindowsShell/SWSH/0624a953ed867ae658abe9a298e5bf3e4d61c65d/.images/logo.png -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at swsh@muzzammil.xyz. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to SWSH 2 | :tada: First off, thanks for taking the time to contribute! :tada: 3 | 4 | ## Index 5 | * [Code Of Conduct](#code-of-conduct) 6 | * [Bug Reporting](#report-a-bug) 7 | * [Feature Request](#add-new-feature) 8 | * [Pull Request](#pull-request) 9 | * [Contact](#contact) 10 | 11 | ## Code Of Conduct 12 | We need you to strictly follow our code of conduct. Help us make a better community. 13 | ### What is Code of conduct? 14 | A code of conduct defines standards for how to engage in a community. It signals an inclusive environment that respects all contributions. It also outlines procedures for addressing problems between members of your project's community. 15 | ### Read our Code of conduct 16 | You can read our code of conduct [here](./CODE_OF_CONDUCT.md) 17 | 18 | ## Report a bug 19 | Before reporting, please ensure that: 20 | - [ ] Bug is not fixed or mentioned in [unstable](https://github.com/muhammadmuzzammil1998/SWSH/tree/unstable) branch of SWSH. 21 | - [ ] Bug is not on your computer only, test it on at least 3 computers. 22 | - [ ] You are using latest version of SWSH. 23 | - [ ] You check if someone already filed a bug report of same issue. (if someone has filed one, comment on it) 24 | - [ ] You do your research to help us identify the problem. 25 | - [ ] You are running the latest version of Windows, SWSH, and .NET framework. 26 | 27 | ### Format of Report 28 | A report should contain the following: 29 | 30 | * A suitable title, 31 | * Your SWSH, Windows, and .NET Framework version, 32 | * Description of what happened and what was supposed to happen, 33 | * Exact steps, 34 | * And, your thought on how to fix this. :) 35 | 36 | #### Example 37 | **Title**: `connect` command is not working. 38 | 39 | **Description**: 40 | 41 | * SWSH Release: Titan 42 | * Windows 10 1709 43 | * .NET framework 4.7 44 | 45 | `connect` command is not working if there is a space before it. 46 | 47 | Steps: just run ` connect` with space. 48 | 49 | Thoughts: Trim input taken from user. 50 | 51 | ## Add new feature 52 | > “The best way to predict your future is to create it.” ~*Abraham Lincoln* 53 | 54 | Just [email us](mailto:swsh@muzzammil.xyz) the details and we will get right on it. 55 | 56 | Details should include: 57 | 58 | * What you want, 59 | * How do you want it, 60 | * Any research you have done for it, 61 | * Your contact information (name, email and website.) 62 | * Anything you want, as long as it follows our [code of conduct](#code-of-conduct). 63 | 64 | ## Pull Request 65 | You can make a pull request, but it should follow guidelines described here and in our [code of conduct](#code-of-conduct). 66 | 67 | ### Somethings to remember when writing code: 68 | * If a function is only required for one function, it should be a local function to the latter function. 69 | Example: 70 | ```cs 71 | // Instead of this: 72 | public static string Name() { 73 | ... 74 | OtherFunction(str); 75 | ... 76 | } 77 | public static string OtherFunction(string s) { 78 | ... 79 | // your code here 80 | ... 81 | } 82 | 83 | 84 | 85 | // Do this: 86 | public static string Name() { 87 | ... 88 | OtherFunction(str); 89 | ... 90 | string OtherFunction(string s) { 91 | ... 92 | // your code here 93 | ... 94 | } 95 | } 96 | ``` 97 | * Try to use lambda. 98 | * Use programmer-friendly variable names. 99 | * Don't do unnecessary things. 100 | 101 | ## Contact 102 | SWSH's email: [swsh@muzzammil.xyz](mailto:swsh@muzzammil.xyz) 103 | 104 | My email: [email@muzzammil.xyz](mailto:email@muzzammil.xyz) 105 | -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | # Documentation for SWSH 2 | 3 | For Titan 4 | 5 | ## Index 6 | 7 | * [Getting Started](#getting-started) 8 | * [Generating SSH keys](#generating-ssh-keys) 9 | * [Importing SSH keys](#importing-ssh-keys) 10 | * [Connecting to a host](#connecting-to-a-host) 11 | * [Commands](#commands) 12 | * [version](#version) 13 | * [connect [nickname]](#connect) 14 | * [keygen](#keygen) 15 | * [help [command]](#help) 16 | * [clear](#clear) 17 | * [pwd](#pwd) 18 | * [computehash [(>/>>) path/to/file]](#computehash) 19 | * [exit](#exit) 20 | * [ls](#ls) 21 | * [cd [arg]](#cd) 22 | * [upload [args] [nickname]:[location]](#upload) 23 | 24 | ## Getting Started 25 | 26 | ### Generating SSH keys 27 | 28 | SSH keys serve as a means of identifying yourself to an SSH server. To Generate your private and public key, SWSH uses an add-on, swsh-keygen. You can [build swsh-keygen](https://github.com/SecureWindowsShell/swsh-keygen) yourself if you want and place the executable (.exe) in SWSH's root (installation) directory. 29 | 30 | Use command ```keygen``` to tell SWSH that you want to generate a new RSA key pair for SSH connection after that just follow the prompts. 31 | You'll be asked for locations to store your keys, leave it blank if you want it to be default. 32 | Output will be similar to this: 33 | 34 | ```swsh 35 | /users/muzzammil:swsh> keygen 36 | 37 | Generating public/private rsa key pair. 38 | exit or -e to cancel. 39 | Enter absolute path to save private key (%appdata%/SWSH/swsh.private): 40 | Enter absolute path to save public key (%appdata%/SWSH/swsh.public): 41 | Your public key: 42 | 43 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCt2MxdswuuUvmaY4JK6kP4lYIqGy0KeHCqcx1NEjB4EcqH7+MIeXGbdikACvP3wlOAEAt+7PMEhBHf7nL2S2SsOybpegJw0piiMeOIPJwQxIQFaRWyz3xn0ESItzBizsQ4yxfQiG37sFkMeQVnP5fHuc2+Z4JZ5SD56Dh1xxgnEw== 44 | ``` 45 | 46 | ### Importing SSH keys 47 | 48 | If you already have SSH keys and want to use them instead of creating a new pair, you can! Use ```keygen import``` command to do so and just follow the prompts. 49 | 50 | NOTE: DO **NOT** SHARE YOUR PRIVATE KEY! 51 | 52 | ### Connecting to a host 53 | 54 | To connect run ```connect username@host```. 55 | 56 | To use a password connection, use tag `-p` like this: ```connect username@host -p```. 57 | 58 | If done properly, output would be similar to the following: 59 | 60 | ```swsh 61 | Waiting for response from username@host... 62 | Connected to username@host... 63 | ~:/ $ 64 | ``` 65 | 66 | ## Commands 67 | 68 | | Command | Description | 69 | |:------------------------------------------|:----------------------------------------------------------------------| 70 | | [version](#version) | Check the version of swsh. | 71 | | [connect [user@host] (-p)](#connect) | Connects to Server over SSH. | 72 | | [keygen (options)](#keygen) | Generates SSH RSA key pair. | 73 | | [help [command]](#help) | Displays this help or command details. | 74 | | [clear](#clear) | Clears the console. | 75 | | [pwd](#pwd) | Prints working directory. | 76 | | [computehash [(>/>>) path]](#computehash) | Uses SHA-1 hash function to generate hashes for SWSH and swsh-keygen. | 77 | | [exit](#exit) | Exits. | 78 | | [ls](#ls) | Lists all files and directories in working directory. | 79 | | [cd [arg]](#cd) | Changes directory to 'arg'. arg = directory name. | 80 | | [upload [arguments]](#upload) | Uploads files and directories. 'upload -h' for help. | 81 | 82 | ### version 83 | 84 | ```swsh 85 | Syntax: version 86 | Checks the version of swsh. 87 | 88 | Usage: version 89 | ``` 90 | 91 | ### connect 92 | 93 | ```swsh 94 | Syntax: connect [user@host] (-p) 95 | Connects to Server over SSH. Use `-p` for password connection. 96 | Usage: connect root@server.ip 97 | ``` 98 | 99 | ### keygen 100 | 101 | ```swsh 102 | Syntax: keygen (options) 103 | Generates, imports or show SSH RSA key pair. Requires swsh-keygen.exe. 104 | Default values are provided in parentheses. 105 | 106 | Options: 107 | import - Imports RSA key pair. 108 | show [private] - Print RSA keys. By default, prints public key. Use `private` to print private key. 109 | ``` 110 | 111 | ### help 112 | 113 | ```swsh 114 | Syntax: help [command] 115 | Displays this help or command details. 116 | Usage: help pwd 117 | ``` 118 | 119 | ### clear 120 | 121 | ```swsh 122 | Syntax: clear 123 | Clears the console. 124 | 125 | Usage: clear 126 | ``` 127 | 128 | ### pwd 129 | 130 | ```swsh 131 | Syntax: pwd 132 | Prints working directory. 133 | Usage: pwd 134 | ``` 135 | 136 | ### computehash 137 | 138 | ```swsh 139 | Syntax: computehash [(>/>>) path/to/file] 140 | Uses SHA-1 hash function to generate hashes for SWSH and swsh-keygen. 141 | 142 | Usage: 143 | To overwrite-> computehash > path/to/file 144 | To append-> computehash >> path/to/file 145 | ``` 146 | 147 | ### exit 148 | 149 | ```swsh 150 | Syntax: exit 151 | Exits. 152 | 153 | Usage: exit 154 | ``` 155 | 156 | ### ls 157 | 158 | ```swsh 159 | Syntax: ls 160 | Lists all files and directories in working directory. 161 | 162 | Usage: ls 163 | ``` 164 | 165 | ### cd 166 | 167 | ```swsh 168 | Syntax: cd [arg] 169 | Changes directory to 'arg'. arg = directory name. 170 | 171 | Usage: cd 172 | ``` 173 | 174 | ### upload 175 | 176 | ```swsh 177 | upload [--dir]* [args] [user@host]:[location] 178 | 179 | 'args' are seperated using spaces ( ) and last 'arg' will be treated as server data which includes username and host location as well as the location of data to upload, part after the colon (:), where the data is to be uploaded. Use flag '--dir' to upload directiories. Do not use absolute paths for local path, change working directory to navigate. 180 | 181 | Usage: upload --dir files root@43.22.56.111:/var/files 182 | ``` 183 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | A report should contain the following: 2 | 3 | * A suitable title, 4 | * Your SWSH, Windows, and .NET Framework version, 5 | * Description of what happened and what was supposed to happen, 6 | * Exact steps, 7 | * And, your thought on how to fix this. :) 8 | 9 | #### Example 10 | **Title**: `connect` command is not working. 11 | 12 | **Description**: 13 | 14 | * SWSH Version: Titan 15 | * Windows 10 1709 16 | * .NET framework 4.7 17 | 18 | `connect` command is not working if there is a space before it. 19 | 20 | Steps: just run ` connect` with space. 21 | 22 | Thoughts: Trim input taken from user. 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |
4 | 5 | Build status 6 | 7 |
8 | 9 | GitHub issues 10 | 11 | 12 | GitHub forks 13 | 14 | 15 | GitHub stars 16 | 17 | 18 | GitHub license 19 | 20 | 21 | Latest release 22 | 23 | Top language 24 | 25 | Website 26 | 27 |

28 | 29 | SWSH is a console application that offers SSH-like connectivity with ease to users which grants them the ability to operate remotely on SSH protocol. It is also Open source, so feel free to contribute. 30 | 31 | **If you are not using a [prebuilt SWSH binary](https://github.com/SecureWindowsShell/SWSH/releases), you will see SWSH complain about a checksum mismatch and exit, use `--IgnoreChecksumMismatch` to stop it from exiting.** 32 | 33 | ![SWSH, just doing its thing](https://user-images.githubusercontent.com/12321712/36885187-8c5fcb12-1e0b-11e8-9ded-62d58dcd3c1e.png) 34 | *SWSH, just doing its thing* 35 | 36 | ## Getting Started 37 | 38 | ### Generating SSH keys 39 | 40 | SSH keys serve as a means of identifying yourself to an SSH server. To Generate your private and public key, SWSH uses an add-on, swsh-keygen. You can [build swsh-keygen](https://github.com/SecureWindowsShell/swsh-keygen) yourself if you want and place the executable (.exe) in SWSH's root (installation) directory. 41 | 42 | Use command ```keygen``` to tell SWSH that you want to generate a new RSA key pair for SSH connection after that just follow the prompts. 43 | You'll be asked for locations to store your keys, leave it blank if you want it to be default. 44 | Output will be similar to this: 45 | 46 | ```swsh 47 | /users/muzzammil:swsh> keygen 48 | 49 | Generating public/private rsa key pair. 50 | exit or -e to cancel. 51 | Enter absolute path to save private key (%appdata%/SWSH/swsh.private): 52 | Enter absolute path to save public key (%appdata%/SWSH/swsh.public): 53 | Your public key: 54 | 55 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCt2MxdswuuUvmaY4JK6kP4lYIqGy0KeHCqcx1NEjB4EcqH7+MIeXGbdikACvP3wlOAEAt+7PMEhBHf7nL2S2SsOybpegJw0piiMeOIPJwQxIQFaRWyz3xn0ESItzBizsQ4yxfQiG37sFkMeQVnP5fHuc2+Z4JZ5SD56Dh1xxgnEw== 56 | ``` 57 | 58 | ### Importing SSH keys 59 | 60 | If you already have SSH keys and want to use them instead of creating a new pair, you can! Use ```keygen import``` command to do so and just follow the prompts. 61 | 62 | NOTE: DO **NOT** SHARE YOUR PRIVATE KEY! 63 | 64 | ### Connecting to a host 65 | 66 | To connect run ```connect username@host```. 67 | 68 | To use a password connection, use tag `-p` like this: ```connect username@host -p```. 69 | 70 | If done properly, output would be similar to the following: 71 | 72 | ```swsh 73 | Waiting for response from username@host... 74 | Connected to username@host... 75 | ~:/ $ 76 | ``` 77 | 78 | ## Commands 79 | 80 | | Command | Description | 81 | |:--------------------------|:----------------------------------------------------------------------| 82 | | version | Check the version of swsh. | 83 | | connect [user@host] (-p) | Connects to Server over SSH. | 84 | | keygen (options) | Generates SSH RSA key pair. | 85 | | help [command] | Displays this help or command details. | 86 | | clear | Clears the console. | 87 | | pwd | Prints working directory. | 88 | | computehash [(>/>>) path] | Uses SHA-1 hash function to generate hashes for SWSH and swsh-keygen. | 89 | | exit | Exits. | 90 | | ls | Lists all files and directories in working directory. | 91 | | cd [arg] | Changes directory to 'arg'. arg = directory name. | 92 | | upload [arguments] | Uploads files and directories. 'upload -h' for help. | 93 | 94 | For more, see our [documentation](DOCUMENTATION.md). 95 | 96 | # License 97 | 98 | GPL v3 99 | 100 | Copyright (C) 2017 Muhammad Muzzammil 101 | -------------------------------------------------------------------------------- /SWSH.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2024 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SWSH", "SWSH\SWSH.csproj", "{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}" 7 | EndProject 8 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Installer", "Installer\Installer.vdproj", "{92400EB6-E01D-4838-A261-0C44A2E50C36}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {92400EB6-E01D-4838-A261-0C44A2E50C36}.Debug|Any CPU.ActiveCfg = Debug 21 | {92400EB6-E01D-4838-A261-0C44A2E50C36}.Release|Any CPU.ActiveCfg = Release 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(ExtensibilityGlobals) = postSolution 27 | SolutionGuid = {88AF42AC-47A4-4255-A7FC-247ECA91CCF2} 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /SWSH/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SWSH/ExternalFunctions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SWSH - Secure Windows Shell 3 | * Copyright (C) 2017 Muhammad Muzzammil 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | using System; 20 | using System.Runtime.InteropServices; 21 | 22 | namespace SWSH { 23 | class ExternalFunctions { 24 | private const string Kernel32 = "kernel32.dll"; 25 | [DllImport(Kernel32, EntryPoint = "SetConsoleMode", SetLastError = true)] 26 | internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode); 27 | [DllImport(Kernel32, EntryPoint = "GetConsoleMode", SetLastError = true)] 28 | internal static extern bool GetConsoleMode(IntPtr handle, out int mode); 29 | [DllImport(Kernel32, EntryPoint = "GetStdHandle", SetLastError = true)] 30 | internal static extern IntPtr GetStdHandle(int handle); 31 | } 32 | } -------------------------------------------------------------------------------- /SWSH/Program.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SWSH - Secure Windows Shell 3 | * Copyright (C) 2017 Muhammad Muzzammil 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Diagnostics; 22 | using System.IO; 23 | using System.Linq; 24 | using System.Net; 25 | using System.Reflection; 26 | using System.Security.Cryptography; 27 | using System.Security.Principal; 28 | using System.Text; 29 | using System.Threading; 30 | using System.Xml; 31 | using Renci.SshNet; 32 | 33 | namespace SWSH { 34 | public static class Program { 35 | public static bool KeygenIsAvailable { get; set; } 36 | public static bool Unstable => Codename.StartsWith("unstable"); 37 | public static string Codename => "Titan (1.0)"; 38 | public static string AppDataDirectory => $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}/SWSH"; 39 | public static string History => $"{AppDataDirectory}/swsh_history"; 40 | public static string Keys => $"{AppDataDirectory}/swsh_keys"; 41 | public static string License => $"{AppDataDirectory}/LICENSE.txt"; 42 | public static string Command { get; set; } 43 | public static string WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); 44 | private static void Main(string[] args) { 45 | if (!Directory.Exists(AppDataDirectory)) Directory.CreateDirectory(AppDataDirectory); 46 | Console.Title = "SWSH - Secure Windows Shell"; 47 | Notice(); 48 | Console.Write("\nType `license notice` to view this notice again.\n"); 49 | for (int i = 0; i < 5; i++) { 50 | Console.Write($"\rStarting in {5 - (i + 1)}s"); 51 | Thread.Sleep(1000); 52 | } 53 | Console.Clear(); 54 | /* Downloading License; if does not exists. START */ 55 | try { 56 | if (!File.Exists(License)) { 57 | Console.WriteLine("License file not found, downloading..."); 58 | new WebClient().DownloadFile(new Uri(Url.License), License); 59 | Console.Clear(); 60 | } 61 | } catch (Exception exp) { Error($"Unable to download License, view online copy here: {Url.License}\nReason:{exp.Message}\n"); } 62 | /* Downloading License; if does not exists. END */ 63 | Console.Title = $"SWSH - {GetVersion()}"; 64 | if (!Unstable) KeygenIsAvailable = CheckHash(args.Any(x => x == "--IgnoreChecksumMismatch")); 65 | Console.Write("Use `help` command for help.\n\n"); 66 | try { 67 | var handle = ExternalFunctions.GetStdHandle(-11); 68 | ExternalFunctions.GetConsoleMode(handle, out var mode); 69 | ExternalFunctions.SetConsoleMode(handle, mode | 0x4); 70 | ExternalFunctions.GetConsoleMode(handle, out mode); 71 | } catch (Exception exp) { Error($"{exp.Message}\n"); } 72 | ReadLine.History = File.ReadAllLines(History).ToList().ConvertAll(x => x.Split('=')[1].Remove(0, 2)); 73 | Console.OutputEncoding = Encoding.UTF8; 74 | Console.InputEncoding = Encoding.UTF8; 75 | Start(); 76 | } 77 | private static void Start() { 78 | while (Command != "exit") { 79 | try { 80 | Color($"{WorkingDirectory.Replace('\\', '/').Remove(0, 2).ToLower()}:", ConsoleColor.DarkCyan); 81 | Color("swsh> ", ConsoleColor.DarkGray); 82 | Command = GetCommand(); 83 | if (Command.StartsWith("swsh")) { 84 | Color( 85 | "WARNING:\nThis type of commands is deprecated and will stop working in future.\nPlease take a look at our latest documentation or" 86 | + " use `help` command.\n", ConsoleColor.Yellow); 87 | if (Command.StartsWith("swsh --")) Command = Command.Remove(0, 7); 88 | } 89 | if (Command == "version") GetVersion(); 90 | else if (Command.StartsWith("help")) Help(null); 91 | else if (Command.StartsWith("connect")) Connect(); 92 | else if (Command.StartsWith("keygen")) Keygen(); 93 | else if (Command.StartsWith("cd")) Cd(); 94 | else if (Command.StartsWith("upload")) Upload(); 95 | else if (Command.StartsWith("computehash")) PrintHash(); 96 | else if (Command == "ls") Ls(); 97 | else if (Command == "clear") Clear(); 98 | else if (Command == "license") File.ReadAllLines(License).ToList().ForEach(Console.WriteLine); 99 | else if (Command == "license notice") Notice(); 100 | else if (Command == "pwd") Console.WriteLine(WorkingDirectory.ToLower()); 101 | else if (Command.Trim() != "") Error($"SWSH -> {Command} -> unknown command.\n"); 102 | } catch (Exception exp) { Error($"{exp.Message}\n"); } 103 | } 104 | } 105 | private static void Help(string cmd) { 106 | Command = cmd ?? Command.Remove(0, 4).Trim(); 107 | if (Command.Length > 0) { 108 | var title = $"Help for {Command}"; 109 | Console.WriteLine(title); 110 | for (int i = 0; i < title.Length; i++) Console.Write("="); 111 | Console.WriteLine(); 112 | switch (Command) { 113 | case "version": 114 | Console.WriteLine("Syntax: version"); 115 | Console.WriteLine("Checks the version of swsh.\n\nUsage: version\n"); 116 | break; 117 | 118 | case "connect": 119 | Console.WriteLine("Syntax: connect [user@host] (-p)"); 120 | Console.WriteLine("Connects to Server over SSH. Use `-p` for password connection.\nUsage: connect root@server.ip"); 121 | break; 122 | 123 | case "keygen": 124 | Console.WriteLine("Syntax: keygen (options)"); 125 | Console.WriteLine("Generates, imports or show SSH RSA key pair. Requires swsh-keygen.exe."); 126 | Console.WriteLine("Default values are provided in parentheses."); 127 | Console.WriteLine("\nOptions:\n\timport\t\t- Imports RSA key pair."); 128 | Console.WriteLine("\tshow [private]\t- Print RSA keys. By default, prints public key. Use `private` to print private key."); 129 | break; 130 | 131 | case "help": 132 | Console.WriteLine("Syntax: help [command]"); 133 | Console.WriteLine("Displays this help or command details.\nUsage: help pwd"); 134 | break; 135 | 136 | case "clear": 137 | Console.WriteLine("Syntax: clear"); 138 | Console.WriteLine("Clears the console.\nUsage: clear"); 139 | break; 140 | 141 | case "pwd": 142 | Console.WriteLine("Syntax: pwd"); 143 | Console.WriteLine("Prints working directory.\nUsage: pwd"); 144 | break; 145 | 146 | case "computehash": 147 | Console.WriteLine("Syntax: computehash [(>/>>) path/to/file]"); 148 | Console.WriteLine("Uses SHA-1 hash function to generate hashes for SWSH and swsh-keygen.\n"); 149 | Console.WriteLine("Usage:\nTo overwrite-> computehash > path/to/file\nTo append-> computehash >> path/to/file"); 150 | break; 151 | 152 | case "ls": 153 | Console.WriteLine("Syntax: ls"); 154 | Console.WriteLine("Lists all files and directories in working directory.\nUsage: ls"); 155 | break; 156 | 157 | case "cd": 158 | Console.WriteLine("Syntax: cd [arg]"); 159 | Console.WriteLine("Changes directory to 'arg'. arg = directory name.\nUsage: cd desktop"); 160 | break; 161 | 162 | case "upload": 163 | Console.WriteLine("Use `upload -h`"); 164 | break; 165 | 166 | default: 167 | Error($"SWSH -> {Command} -> unknown command.\n"); 168 | break; 169 | } 170 | } else { 171 | Console.Write( 172 | "Usage: [arguments] (options)\n" 173 | + "Available commands:\n" 174 | + " version -Check the version of swsh.\n" 175 | + " connect [user@host] (-p) -Connects to Server over SSH.\n" 176 | + " keygen (options) -Generates, imports or show SSH RSA key pair. `help keygen` for more.\n" 177 | + " help [command] -Displays this help or command details.\n" 178 | + " clear -Clears the console.\n" 179 | + " pwd -Prints working directory.\n" 180 | + " computehash [(>/>>) path] -Uses SHA-1 hash function to generate hashes for SWSH and swsh-keygen.\n" 181 | + " exit -Exits.\n" 182 | + " ls -Lists all files and directories in working directory.\n" 183 | + " cd [arg] -Changes directory to 'arg'. arg = directory name.\n" 184 | + " upload [arguments] -Uploads files and directories. 'upload -h' for help.\n"); 185 | } 186 | } 187 | private static void Connect() { 188 | if (Command.Length <= 8) { 189 | Help("connect"); 190 | return; 191 | } 192 | if (!Command.EndsWith("-p")) { 193 | if (!File.Exists(Keys)) { 194 | Console.Write("SWSH private key file not found. (I)mport or (G)enerate?: "); 195 | switch (Console.ReadKey().Key) { 196 | case ConsoleKey.I: 197 | ImportKey(); 198 | break; 199 | case ConsoleKey.G: 200 | Keygen(); 201 | break; 202 | default: 203 | Console.WriteLine(" <= Invalid option."); 204 | return; 205 | } 206 | return; 207 | } 208 | if (string.IsNullOrEmpty(ReadKeys()[1])) Color("WARNING: No public key detected.\n", ConsoleColor.Yellow); 209 | } 210 | 211 | var ccinfo = CreateConnection(Command.Remove(0, 8)); 212 | if (ccinfo == null) return; 213 | Console.Write($"Waiting for response from {ccinfo.Username}@{ccinfo.Host}...\n"); 214 | using (var ssh = new SshClient(ccinfo)) { 215 | ssh.Connect(); 216 | Color($"Connected to {ccinfo.Username}@{ccinfo.Host}...\n", ConsoleColor.Green); 217 | var actual = ssh.CreateShellStream( 218 | "xterm-256color", 219 | (uint)Console.BufferWidth, 220 | (uint)Console.BufferHeight, 221 | (uint)Console.BufferWidth, 222 | (uint)Console.BufferHeight, 223 | Console.BufferHeight, null); 224 | //Read Thread 225 | var read = new Thread(() => { 226 | if (!actual.CanRead) return; 227 | while (true) 228 | Console.WriteLine(actual.ReadLine()); 229 | }); 230 | //Write Thread 231 | new Thread(() => { 232 | if (!actual.CanWrite) return; 233 | while (true) { 234 | try { 235 | actual.WriteLine(""); 236 | var input = Console.ReadLine(); 237 | Console.Write("\b\r\b\r"); 238 | actual.WriteLine(input); 239 | if (input != "exit") continue; 240 | actual.Dispose(); 241 | read.Abort(); 242 | throw new Exception(); 243 | } catch (Exception) { 244 | Color($"Connection to {ccinfo.Username}@{ccinfo.Host}, closed.\n", 245 | ConsoleColor.Yellow); 246 | Color("(E)xit SWSH - Any other key to reload SWSH: ", ConsoleColor.Blue); 247 | var key = Console.ReadKey(); 248 | if (key.Key != ConsoleKey.E) 249 | Process.Start(Assembly.GetExecutingAssembly().Location); 250 | ssh.Disconnect(); 251 | Environment.Exit(0); 252 | } 253 | } 254 | }).Start(); 255 | read.Start(); 256 | while (true) { } 257 | } 258 | } 259 | private static void ImportKey() { 260 | string[] data = new string[2]; 261 | Console.WriteLine("\nImporting keys..."); 262 | while (true) { 263 | Console.Write("Enter path to private key: "); 264 | data[0] = GetCommand(); 265 | if (data[0].Trim() == string.Empty) 266 | Error("SWSH -> key path should not be empty!\n"); 267 | else { 268 | if (File.Exists(data[0]) && File.Exists($"{WorkingDirectory}/{data[0]}")) 269 | Error($"SWSH -> {data[0]} -> file path is ambiguous.\n"); 270 | else if (File.Exists($"{WorkingDirectory}/{data[0]}")) { 271 | data[0] = $"{WorkingDirectory.Replace('\\', '/')}/{data[0]}"; 272 | break; 273 | } else if (!File.Exists(data[0])) 274 | Error($"SWSH -> {data[0]} -> file is non existent.\n"); 275 | else break; 276 | } 277 | } 278 | Console.Write("Import public key? (y/n): "); 279 | if (GetCommand().ToUpper() == "Y") { 280 | while (true) { 281 | Console.Write("Enter path to public key: "); 282 | data[1] = GetCommand(); 283 | if (data[1].Trim() == string.Empty) 284 | Error("SWSH -> key path should not be empty!\n"); 285 | else { 286 | if (File.Exists(data[1]) && File.Exists($"{WorkingDirectory}/{data[1]}")) 287 | Error($"SWSH -> {data[1]} -> file path is ambiguous.\n"); 288 | else if (File.Exists($"{WorkingDirectory}/{data[0]}")) { 289 | data[0] = $"{WorkingDirectory.Replace('\\', '/')}/{data[0]}"; 290 | break; 291 | } else if (!File.Exists(data[1])) 292 | Error($"SWSH -> {data[1]} -> file is non existent.\n"); 293 | else break; 294 | } 295 | } 296 | } else Console.Write("\r\b\rImport public key? (y/n): ...skipped\n"); 297 | WriteKeys(data[0], data[1] ?? ""); 298 | } 299 | private static void Keygen() { 300 | Command = Command.Length > 7 ? Command.Remove(0, 7) : null; 301 | if (Command != null && Command.StartsWith("show")) { 302 | if (Command.Remove(0, 4).Trim() == "private") { 303 | Console.WriteLine(ReadKeys()[0]); 304 | } else Console.WriteLine(!string.IsNullOrEmpty(ReadKeys()[1]) ? ReadKeys()[1] : "No public key detected."); 305 | return; 306 | } 307 | if (File.Exists(Keys)) { 308 | Color( 309 | "WARNING: This action will overwrite previously generated or imported keys in the data file but not the original keys. Continue? (y/n): ", 310 | ConsoleColor.Yellow); 311 | if (Console.ReadKey().Key != ConsoleKey.Y) { 312 | Console.WriteLine(); 313 | return; 314 | } 315 | } 316 | if (Command == "import") { 317 | ImportKey(); 318 | return; 319 | } 320 | if (!KeygenIsAvailable ^ Unstable) { 321 | Color("Key generation is unavailable.\n", ConsoleColor.DarkBlue); 322 | return; 323 | } 324 | if (File.Exists("swsh-keygen.exe")) { 325 | if (!CheckHash(true) ^ Unstable) return; 326 | Console.WriteLine("\nGenerating public/private rsa key pair."); 327 | string privateFile, publicFile; 328 | Color("exit", ConsoleColor.Red); 329 | Console.Write(" or "); 330 | Color("-e", ConsoleColor.Red); 331 | Console.Write(" to cancel.\n"); 332 | do { 333 | Color("Enter absolute path to save private key (%appdata%/SWSH/swsh.private):\t", ConsoleColor.Yellow); 334 | privateFile = GetCommand(); 335 | if (privateFile == string.Empty) privateFile = AppDataDirectory + "/swsh.private"; 336 | else if (privateFile == "-e" || privateFile == "exit") return; 337 | } while (!IsWritable(privateFile)); 338 | do { 339 | Color("Enter absolute path to save public key (%appdata%/SWSH/swsh.public):\t", ConsoleColor.Yellow); 340 | publicFile = GetCommand(); 341 | if (publicFile == string.Empty) publicFile = AppDataDirectory + "/swsh.public"; 342 | else if (publicFile == "-e" || privateFile == "exit") return; 343 | } while (!IsWritable(publicFile)); 344 | bool IsWritable(string path) { 345 | if (!File.Exists(path)) return true; 346 | Color($"File exists: {new FileInfo(path).FullName}\n\n\nOverwrite? (y/n): ", ConsoleColor.Red); 347 | return GetCommand().ToUpper() == "Y"; 348 | } 349 | var keygenProcess = new Process { 350 | StartInfo = new ProcessStartInfo { 351 | FileName = "swsh-keygen.exe", 352 | Arguments = $"-pub={new FileInfo(publicFile).FullName} -pri={new FileInfo(privateFile).FullName}", 353 | RedirectStandardOutput = true, 354 | UseShellExecute = false, 355 | CreateNoWindow = true 356 | } 357 | }; 358 | keygenProcess.Start(); 359 | keygenProcess.WaitForExit(); 360 | if (keygenProcess.ExitCode != 0) { 361 | Color($"WARNING: swsh-keygen exited with exit code {keygenProcess.ExitCode}.", ConsoleColor.Yellow); 362 | return; 363 | } 364 | Color($"Your public key:\n\n{File.ReadAllLines(publicFile)[0]}\n", ConsoleColor.Green); 365 | WriteKeys(privateFile, publicFile); 366 | } else Error($"The binary 'swsh-keygen.exe' was not found. Are you sure it's installed?\nSee: {Url.Keygen}.\n"); 367 | } 368 | private static void Clear() { 369 | Console.Clear(); 370 | GetVersion(); 371 | Console.Write("Use `help` command for help.\n\n"); 372 | } 373 | private static void Ls() { 374 | if (Directory.GetDirectories(WorkingDirectory).Length > 0) { 375 | var data = new List(); 376 | Directory.GetDirectories(WorkingDirectory).ToList().ForEach(dir => data.Add(dir)); 377 | Directory.GetFiles(WorkingDirectory).ToList().ForEach(file => data.Add(file)); 378 | data.Sort(); 379 | Console.WriteLine("Size\tUser Date Modified Name\n====\t==== ============= ===="); 380 | data.ForEach(x => { 381 | if (File.Exists(x)) { 382 | var info = new FileInfo(x); 383 | if (info.Attributes.ToString().Contains("Hidden")) return; 384 | var owner = File.GetAccessControl(x).GetOwner(typeof(NTAccount)).ToString().Split('\\')[1]; 385 | var size = (info.Length > 1024 ? (info.Length / 1024 > 1024 ? info.Length / 1024 / 1024 : info.Length / 1024) : 386 | info.Length).ToString(); 387 | var toApp = ""; 388 | owner = owner.Length >= 10 ? owner.Remove(5) + "..." + owner.Remove(0, owner.Length - 2) : owner; 389 | if (owner.Length < 10) for (int i = 0; i < 10 - owner.Length; i++) toApp += " "; 390 | owner += toApp; 391 | if (size.Length < 4) for (int i = 0; i < 3 - size.Length; i++) toApp += " "; 392 | size = toApp + size; 393 | Color(size, ConsoleColor.Green); 394 | Color(info.Length > 1024 ? (info.Length / 1024 > 1024 ? "MB" : "KB") : "B", ConsoleColor.DarkGreen); 395 | Color($"\t{owner} ", ConsoleColor.Yellow); 396 | Color( 397 | $"{($"{info.LastWriteTime.Date:d}".Split('/')[0].Length > 1 ? "" : " ")}" + 398 | $"{$"{info.LastWriteTime.Date:d}".Split('/')[0]} " + 399 | $"{$"{info.LastWriteTime.Date:m}".Remove(3)} " + 400 | $"{info.LastWriteTime.ToLocalTime():HH:mm} ", 401 | ConsoleColor.Blue); 402 | Color(info.Name, Path.GetFileNameWithoutExtension(x).Length > 0 ? ConsoleColor.Magenta : ConsoleColor.Cyan); 403 | Console.WriteLine(); 404 | } else if (Directory.Exists(x)) { 405 | var info = new DirectoryInfo(x); 406 | if (info.Attributes.ToString().Contains("Hidden")) return; 407 | var owner = File.GetAccessControl(x).GetOwner(typeof(NTAccount)).ToString().Split('\\')[1]; 408 | owner = owner.Length >= 10 ? owner.Remove(5) + "..." + owner.Remove(0, owner.Length - 2) : owner; 409 | var toApp = ""; 410 | if (owner.Length < 10) for (int i = 0; i < 10 - owner.Length; i++) toApp += " "; 411 | owner += toApp; 412 | Color(" -", ConsoleColor.DarkGray); 413 | Color($"\t{owner} ", ConsoleColor.Yellow); 414 | Color( 415 | $"{($"{info.LastWriteTime.Date:d}".Split('/')[0].Length > 1 ? "" : " ")}" + 416 | $"{$"{info.LastWriteTime.Date:d}".Split('/')[0]} " + 417 | $"{$"{info.LastWriteTime.Date:m}".Remove(3)} " + 418 | $"{info.LastWriteTime.ToLocalTime():HH:mm} ", 419 | ConsoleColor.Blue); 420 | Color(info.Name, 421 | info.Name.StartsWith(".") ? ConsoleColor.DarkCyan : info.GetFiles().Length > 0 || info.GetDirectories().Length > 0 ? 422 | ConsoleColor.White : ConsoleColor.DarkGray); 423 | Color(info.GetFiles().Length == 0 && info.GetDirectories().Length == 0 ? " " : "", ConsoleColor.DarkRed); 424 | Console.WriteLine(); 425 | } 426 | }); 427 | } 428 | if (Directory.GetDirectories(WorkingDirectory).Length == 0 && Directory.GetFiles(WorkingDirectory).Length == 0) 429 | Color("No files or directories here.\n", ConsoleColor.Yellow); 430 | } 431 | private static void Cd() { 432 | if (Command.Length <= 3) { 433 | Help("cd"); 434 | return; 435 | } 436 | if ((Command = Command.Remove(0, 3)) == "..") ChangeWorkingDir(Path.GetDirectoryName(WorkingDirectory)); 437 | else if (Command.StartsWith("./")) ChangeWorkingDir($"{WorkingDirectory}/{Command.Remove(0, 2)}"); 438 | else if (Command.StartsWith("/")) ChangeWorkingDir(Path.GetPathRoot(WorkingDirectory) + Command.Remove(0, 1)); 439 | else ChangeWorkingDir($"{WorkingDirectory}/{Command}"); 440 | void ChangeWorkingDir(string path) { 441 | path = path.Replace('\\', '/'); 442 | if (Directory.Exists(Path.GetFullPath(path))) WorkingDirectory = Path.GetFullPath(path); 443 | else Error($"SWSH -> {path} -> path does not exists.\n"); 444 | } 445 | } 446 | private static void Upload() { 447 | if (Command.Length <= 7) { 448 | Command = "upload -h"; 449 | } 450 | if ((Command = Command.Remove(0, 7)) == "-h") { 451 | Console.WriteLine( 452 | "upload [--dir]* [args] [user@host]:[location]\n\n'args' are seperated using spaces ( ) and last 'arg' will be treated as server data whic" 453 | + "h includes username and host location as well as the location of data to upload, part after the colon (:), where the data is to be uplo" 454 | + "aded. Use flag '--dir' to upload directiories. Do not use absolute paths for local path, change working directory to navigate."); 455 | } else { 456 | var toupload = Command.StartsWith("--dir") ? Command.Replace("--dir", "").Trim().Split(' ').ToList() : Command.Trim().Split(' ').ToList(); 457 | try { 458 | var serverData = toupload.Pop().Split(':'); 459 | var data = serverData[0]; 460 | var location = serverData[1]; 461 | try { 462 | var ccinfo = CreateConnection(data); 463 | if (ccinfo != null) { 464 | if (Command.StartsWith("--dir")) 465 | using (var sftp = new SftpClient(ccinfo)) { 466 | Command = Command.Replace("--dir", ""); 467 | sftp.Connect(); 468 | toupload.ForEach(x => { 469 | var path = $"{WorkingDirectory}/{x.Trim()}"; 470 | location = serverData[1] + (serverData[1].EndsWith("/") ? "" : "/") + 471 | x.Trim(); 472 | if (!sftp.Exists(location)) sftp.CreateDirectory(location); 473 | Color($"Uploading : {x.Trim()}\n", ConsoleColor.Yellow); 474 | UploadDir(sftp, path, location); 475 | Color("Done.\n", ConsoleColor.Green); 476 | }); 477 | } else 478 | using (var scp = new ScpClient(ccinfo)) { 479 | scp.Connect(); 480 | toupload.ForEach(x => { 481 | var path = $"{WorkingDirectory}/{x.Trim()}"; 482 | if (File.Exists(path)) { 483 | Color($"Uploading : {x.Trim()}", ConsoleColor.Yellow); 484 | scp.Upload(new FileInfo(path), location); 485 | Color(" -> Done\n", ConsoleColor.Green); 486 | } else Error($"SWSH -> {path.Replace('/', '\\')} -> file does not exists.\n"); 487 | }); 488 | } 489 | } 490 | } catch (Exception exp) { Error($"{exp.Message}\n"); } 491 | } catch { Error($"SWSH -> upload {Command} -> is not the correct syntax for this command.\n"); } 492 | } 493 | void UploadDir(SftpClient client, string localPath, string remotePath) { 494 | new DirectoryInfo(localPath).EnumerateFileSystemInfos().ToList().ForEach(x => { 495 | if (x.Attributes.HasFlag(FileAttributes.Directory)) { 496 | var subPath = $"{remotePath}/{x.Name}"; 497 | if (!client.Exists(subPath)) client.CreateDirectory(subPath); 498 | UploadDir(client, x.FullName, $"{remotePath}/{x.Name}"); 499 | } else { 500 | using (Stream fileStream = new FileStream(x.FullName, FileMode.Open)) { 501 | Console.ForegroundColor = ConsoleColor.Yellow; 502 | Console.Write($"\tUploading : {x} ({((FileInfo)x).Length:N0} bytes)"); 503 | client.UploadFile(fileStream, $"{remotePath}/{x.Name}"); 504 | Color(" -> Done\n", ConsoleColor.Green); 505 | } 506 | } 507 | }); 508 | } 509 | } 510 | private static string Pop(this IList list) { 511 | var retVal = list[list.Count - 1]; 512 | list.RemoveAt(list.Count - 1); 513 | return retVal; 514 | } 515 | private static string GetVersion() { 516 | Console.Write( 517 | " ______ _______ __ __\n / ___/ | / / ___// / / /\n \\__ \\| | /| / /\\__ \\/ /_/ / \n ___/ /| |/ |/ /___/ / __ / \n/____/ |_" 518 | + "_/|__//____/_/ /_/ \n Secure Windows Shell \n"); 519 | Console.Write($"\nRelease: {Codename}\n"); 520 | return $"{Codename} {(new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)? "(Administrator)" : "")}"; 521 | } 522 | private static void Color(string message, ConsoleColor cc) { 523 | Console.ForegroundColor = cc; 524 | Console.Write(message); 525 | Console.ResetColor(); 526 | } 527 | private static bool CheckHash(bool ignore) { 528 | bool CompareHash(string path, string hash) => !ComputeHash(path).Equals(hash.Trim()); 529 | string GetHash(string uri) => new WebClient().DownloadString($"{uri}?" + new Random().Next()); 530 | string 531 | error = "ERROR: Checksum Mismatch! This executable *may* be out of date or malicious!\n", 532 | checksumfile = Url.Checksum, 533 | swshlocation = Assembly.GetExecutingAssembly().Location, 534 | keygenlocation = "swsh-keygen.exe"; 535 | try { 536 | if (CompareHash(swshlocation, GetHash(checksumfile).Split(' ')[0]) || CompareHash(keygenlocation, GetHash(checksumfile).Split(' ')[1])) 537 | throw new Exception(); 538 | return true; 539 | } catch (Exception) { 540 | if (!File.Exists(keygenlocation)) { 541 | Color("WARNING: Could not find swsh-keygen.exe. SSH key generation will not be available.\n", ConsoleColor.Yellow); 542 | } 543 | if (!ignore) { 544 | Color(error, ConsoleColor.Red); 545 | Console.Read(); 546 | Environment.Exit(500); 547 | } 548 | return false; 549 | } 550 | } 551 | private static void PrintHash() { 552 | string action = Command.Remove(0, 11).Trim(); 553 | if (action.StartsWith(">") && File.Exists("swsh-keygen.exe")) { 554 | Color("Exporting... ", ConsoleColor.Yellow); 555 | string file; 556 | if (action.StartsWith(">>")) { 557 | file = action.Remove(0, 2).Trim(); 558 | File.AppendAllText(file, $"{ComputeHash(Assembly.GetExecutingAssembly().Location)} {ComputeHash("swsh-keygen.exe")}"); 559 | Console.WriteLine(new FileInfo(file).FullName); 560 | return; 561 | } 562 | file = action.Remove(0, 1).Trim(); 563 | File.WriteAllText(file, $"{ComputeHash(Assembly.GetExecutingAssembly().Location)} {ComputeHash("swsh-keygen.exe")}"); 564 | Console.WriteLine(new FileInfo(file).FullName); 565 | return; 566 | } 567 | Console.WriteLine($"{ComputeHash(Assembly.GetExecutingAssembly().Location)} -- SHA1 -- SWSH.exe"); 568 | if (File.Exists("swsh-keygen.exe")) Console.WriteLine($"{ComputeHash("swsh-keygen.exe")} -- SHA1 -- swsh-keygen.exe"); 569 | } 570 | private static string ComputeHash(string path) => 571 | new List(new SHA1CryptoServiceProvider() 572 | .ComputeHash(File.ReadAllBytes(path))) 573 | .Select(x => x.ToString("x2")) 574 | .Aggregate((x, y) => x + y); 575 | private static void Notice() => 576 | Console.Write("SWSH - Secure Windows Shell\nCopyright (C) 2017 Muhammad Muzzammil\nThis program comes with ABSOLUTELY NO WARRANTY; for details ty" 577 | + "pe `license'.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; type `license' for detail" 578 | + "s.\n\n"); 579 | private static string GetCommand() { 580 | var commands = new[] { "version", "connect", "keygen", "help", "clear", "exit", "upload", "pwd", "computehash" }; 581 | var list = commands.ToList(); 582 | list.AddRange(Directory.GetDirectories(WorkingDirectory).Select(i => $"cd {new DirectoryInfo(i).Name.ToLower()}")); 583 | try { 584 | ReadLine.AutoCompletionHandler = (data, length) => { 585 | var tList = new List(); 586 | if (data.StartsWith("cd ") && (data.Contains("/") || data.Contains("\\"))) 587 | Directory.GetDirectories($"{WorkingDirectory}/{Path.GetDirectoryName(data.Remove(0, 3))}").ToList() 588 | .Where(x => new DirectoryInfo(x) 589 | .FullName.ToLower().Contains(data.ToLower().Split(' ')[1].Replace('/', '\\'))).ToList() 590 | .ForEach(x => tList.Add(x.Remove(0, $"{WorkingDirectory}/{Path.GetDirectoryName(data.Remove(0, 3))}".Length + 1).ToLower())); 591 | if (data.Trim() == "help") 592 | commands.ToList().ForEach(x => tList.Add(x)); 593 | list.Where(x => x.Contains(data)).ToList().ForEach(y => tList.Add(y.Remove(0, length))); 594 | return tList.ToArray(); 595 | }; 596 | } catch (IndexOutOfRangeException) { } 597 | var read = ReadLine.Read(); 598 | File.AppendAllText(History, $"[{DateTime.UtcNow} UTC]\t=>\t{read}\n"); 599 | if (read.Contains("%appdata%")) 600 | read = read.Replace("%appdata%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace('\\', '/')); 601 | return read.TrimEnd().TrimStart().Trim(); 602 | } 603 | private static string GetPassword(string prompt) { 604 | ReadLine.PasswordMode = true; 605 | var password = ReadLine.Read(prompt); 606 | ReadLine.GetHistory().Pop(); 607 | ReadLine.PasswordMode = false; 608 | return password; 609 | } 610 | private static void Error(string err) { 611 | Color("ERROR: ", ConsoleColor.Red); 612 | Console.Write(err); 613 | } 614 | private static string[] ReadKeys() { 615 | var xml = new XmlDocument(); 616 | xml.Load(Keys); 617 | return new[] { xml.GetElementsByTagName("private")[0].InnerText, xml.GetElementsByTagName("public")[0].InnerText }; 618 | } 619 | private static void WriteKeys(string privateFile, string publicFile) { 620 | var publickey = publicFile == null ? "" : File.ReadAllText(new FileInfo(publicFile).FullName); 621 | File.WriteAllLines(Keys, new[] { 622 | "", 623 | "", 624 | $"{File.ReadAllText(new FileInfo(privateFile).FullName)}", 625 | $"{publickey}", 626 | "" 627 | }); 628 | } 629 | private static ConnectionInfo CreateConnection(string data) { 630 | try { 631 | if (data.EndsWith("-p")) { 632 | data = data.Split(' ')[0]; 633 | return new ConnectionInfo( 634 | data.Split('@')[1], 635 | data.Split('@')[0], 636 | new PasswordAuthenticationMethod( 637 | data.Split('@')[0], 638 | GetPassword($"Password for {data}: "))); 639 | } 640 | return new ConnectionInfo( 641 | data.Split('@')[1], 642 | data.Split('@')[0], 643 | new PrivateKeyAuthenticationMethod( 644 | data.Split('@')[0], 645 | new PrivateKeyFile(new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(ReadKeys()[0]))).BaseStream))); 646 | } catch (Exception exp) { Error($"{exp.Message}\n"); } 647 | return null; 648 | } 649 | } 650 | } -------------------------------------------------------------------------------- /SWSH/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SWSH - Secure Windows Shell 3 | * Copyright (C) 2017 Muhammad Muzzammil 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | using System.Reflection; 20 | using System.Runtime.InteropServices; 21 | 22 | // General Information about an assembly is controlled through the following 23 | // set of attributes. Change these attribute values to modify the information 24 | // associated with an assembly. 25 | [assembly: AssemblyTitle("SWSH")] 26 | [assembly: AssemblyDescription("Licensed under the GNU GPL v3")] 27 | [assembly: AssemblyConfiguration("")] 28 | [assembly: AssemblyCompany("Secure Windows Shell")] 29 | [assembly: AssemblyProduct("SWSH")] 30 | [assembly: AssemblyCopyright("Copyright © 2017 Muhammad Muzzammil")] 31 | [assembly: AssemblyTrademark("SWSH")] 32 | [assembly: AssemblyCulture("")] 33 | 34 | // Setting ComVisible to false makes the types in this assembly not visible 35 | // to COM components. If you need to access a type in this assembly from 36 | // COM, set the ComVisible attribute to true on that type. 37 | [assembly: ComVisible(false)] 38 | 39 | // The following GUID is for the ID of the typelib if this project is exposed to COM 40 | [assembly: Guid("6a30c4d1-0e4f-49b9-b2b2-d210923ce44c")] 41 | 42 | // Version information for an assembly consists of the following four values: 43 | // 44 | // Major Version 45 | // Minor Version 46 | // Build Number 47 | // Revision 48 | // 49 | // You can specify all the values or you can default the Build and Revision Numbers 50 | // by using the '*' as shown below: 51 | // [assembly: AssemblyVersion("1.0.*")] 52 | [assembly: AssemblyVersion("1.0")] 53 | [assembly: AssemblyFileVersion("1.0")] 54 | -------------------------------------------------------------------------------- /SWSH/ReadLine.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * https://github.com/tonerdo/readline/blob/master/LICENSE 3 | * The MIT License(MIT) 4 | * 5 | * Copyright(c) 2017 Toni Solarin-Sodara 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | */ 17 | 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Text; 21 | 22 | namespace SWSH { 23 | public static class ReadLine { 24 | private static KeyHandler _keyHandler; 25 | public static List History; 26 | public static List GetHistory() => History; 27 | public static Func AutoCompletionHandler { private get; set; } 28 | public static bool PasswordMode { private get; set; } 29 | public static string Read(string prompt = "", string defaultInput = "") { 30 | Console.Write(prompt); 31 | 32 | _keyHandler = new KeyHandler(new Console2() { PasswordMode = PasswordMode }, History, AutoCompletionHandler); 33 | ConsoleKeyInfo keyInfo = Console.ReadKey(true); 34 | 35 | while (keyInfo.Key != ConsoleKey.Enter) { 36 | _keyHandler.Handle(keyInfo); 37 | keyInfo = Console.ReadKey(true); 38 | } 39 | 40 | Console.WriteLine(); 41 | 42 | string text = _keyHandler.Text; 43 | if (String.IsNullOrWhiteSpace(text) && !String.IsNullOrWhiteSpace(defaultInput)) 44 | text = defaultInput; 45 | else 46 | History.Add(text); 47 | 48 | return text; 49 | } 50 | } 51 | internal class KeyHandler { 52 | private int _cursorPos; 53 | private int _cursorLimit; 54 | private readonly StringBuilder _text; 55 | private readonly List _history; 56 | private int _historyIndex; 57 | private ConsoleKeyInfo _keyInfo; 58 | private readonly Dictionary _keyActions; 59 | private string[] _completions; 60 | private int _completionStart; 61 | private int _completionsIndex; 62 | private readonly IConsole _console2; 63 | 64 | private bool IsStartOfLine() => _cursorPos == 0; 65 | private bool IsEndOfLine() => _cursorPos == _cursorLimit; 66 | private bool IsStartOfBuffer() => _console2.CursorLeft == 0; 67 | private bool IsEndOfBuffer() => _console2.CursorLeft == _console2.BufferWidth - 1; 68 | private bool IsInAutoCompleteMode() => _completions != null; 69 | private void MoveCursorLeft() { 70 | if (IsStartOfLine()) 71 | return; 72 | if (IsStartOfBuffer()) 73 | _console2.SetCursorPosition(_console2.BufferWidth - 1, _console2.CursorTop - 1); 74 | else 75 | _console2.SetCursorPosition(_console2.CursorLeft - 1, _console2.CursorTop); 76 | _cursorPos--; 77 | } 78 | private void MoveCursorHome() { 79 | while (!IsStartOfLine()) 80 | MoveCursorLeft(); 81 | } 82 | private string BuildKeyInput() { 83 | return (_keyInfo.Modifiers != ConsoleModifiers.Control && _keyInfo.Modifiers != ConsoleModifiers.Shift) ? 84 | _keyInfo.Key.ToString() : _keyInfo.Modifiers.ToString() + _keyInfo.Key.ToString(); 85 | } 86 | private void MoveCursorRight() { 87 | if (IsEndOfLine()) 88 | return; 89 | if (IsEndOfBuffer()) 90 | _console2.SetCursorPosition(0, _console2.CursorTop + 1); 91 | else 92 | _console2.SetCursorPosition(_console2.CursorLeft + 1, _console2.CursorTop); 93 | _cursorPos++; 94 | } 95 | private void MoveCursorEnd() { 96 | while (!IsEndOfLine()) 97 | MoveCursorRight(); 98 | } 99 | private void ClearLine() { 100 | MoveCursorEnd(); 101 | while (!IsStartOfLine()) 102 | Backspace(); 103 | } 104 | private void WriteNewString(string str) { 105 | ClearLine(); 106 | foreach (char character in str) 107 | WriteChar(character); 108 | } 109 | private void WriteString(string str) { 110 | foreach (char character in str) 111 | WriteChar(character); 112 | } 113 | private void WriteChar() => WriteChar(_keyInfo.KeyChar); 114 | private void WriteChar(char c) { 115 | if (IsEndOfLine()) { 116 | _text.Append(c); 117 | _console2.Write(c.ToString()); 118 | _cursorPos++; 119 | } else { 120 | int left = _console2.CursorLeft; 121 | int top = _console2.CursorTop; 122 | string str = _text.ToString().Substring(_cursorPos); 123 | _text.Insert(_cursorPos, c); 124 | _console2.Write(c.ToString() + str); 125 | _console2.SetCursorPosition(left, top); 126 | MoveCursorRight(); 127 | } 128 | _cursorLimit++; 129 | } 130 | private void Backspace() { 131 | if (IsStartOfLine()) 132 | return; 133 | MoveCursorLeft(); 134 | int index = _cursorPos; 135 | _text.Remove(index, 1); 136 | string replacement = _text.ToString().Substring(index); 137 | int left = _console2.CursorLeft; 138 | int top = _console2.CursorTop; 139 | _console2.Write($"{replacement} "); 140 | _console2.SetCursorPosition(left, top); 141 | _cursorLimit--; 142 | } 143 | private void StartAutoComplete() { 144 | while (_cursorPos > _completionStart) 145 | Backspace(); 146 | 147 | _completionsIndex = 0; 148 | 149 | WriteString(_completions[_completionsIndex]); 150 | } 151 | private void NextAutoComplete() { 152 | while (_cursorPos > _completionStart) 153 | Backspace(); 154 | 155 | _completionsIndex++; 156 | 157 | if (_completionsIndex == _completions.Length) 158 | _completionsIndex = 0; 159 | 160 | WriteString(_completions[_completionsIndex]); 161 | } 162 | private void PreviousAutoComplete() { 163 | while (_cursorPos > _completionStart) 164 | Backspace(); 165 | 166 | _completionsIndex--; 167 | 168 | if (_completionsIndex == -1) 169 | _completionsIndex = _completions.Length - 1; 170 | 171 | WriteString(_completions[_completionsIndex]); 172 | } 173 | private void PrevHistory() { 174 | if (_historyIndex > 0) { 175 | _historyIndex--; 176 | WriteNewString(_history[_historyIndex]); 177 | } 178 | } 179 | private void NextHistory() { 180 | if (_historyIndex < _history.Count) { 181 | _historyIndex++; 182 | if (_historyIndex == _history.Count) 183 | ClearLine(); 184 | else 185 | WriteNewString(_history[_historyIndex]); 186 | } 187 | } 188 | private void ResetAutoComplete() { 189 | _completions = null; 190 | _completionsIndex = 0; 191 | } 192 | public string Text => _text.ToString(); 193 | public KeyHandler(IConsole console, List history, Func autoCompleteHandler) { 194 | _console2 = console; 195 | 196 | _historyIndex = history.Count; 197 | _history = history; 198 | _text = new StringBuilder(); 199 | _keyActions = new Dictionary { 200 | ["LeftArrow"] = MoveCursorLeft, 201 | ["Home"] = MoveCursorHome, 202 | ["End"] = MoveCursorEnd, 203 | ["ControlA"] = MoveCursorHome, 204 | ["ControlB"] = MoveCursorLeft, 205 | ["RightArrow"] = MoveCursorRight, 206 | ["ControlF"] = MoveCursorRight, 207 | ["ControlE"] = MoveCursorEnd, 208 | ["Backspace"] = Backspace, 209 | ["ControlH"] = Backspace, 210 | ["ControlL"] = ClearLine, 211 | ["UpArrow"] = PrevHistory, 212 | ["ControlP"] = PrevHistory, 213 | ["DownArrow"] = NextHistory, 214 | ["ControlN"] = NextHistory, 215 | ["ControlU"] = () => { 216 | while (!IsStartOfLine()) 217 | Backspace(); 218 | }, 219 | ["ControlK"] = () => { 220 | int pos = _cursorPos; 221 | MoveCursorEnd(); 222 | while (_cursorPos > pos) 223 | Backspace(); 224 | }, 225 | ["ControlW"] = () => { 226 | while (!IsStartOfLine() && _text[_cursorPos - 1] != ' ') 227 | Backspace(); 228 | }, 229 | 230 | ["Tab"] = () => { 231 | if (IsInAutoCompleteMode()) { 232 | NextAutoComplete(); 233 | } else { 234 | if (autoCompleteHandler == null || !IsEndOfLine()) 235 | return; 236 | 237 | char[] anyOf = new char[] { ' ', '.', '/', '\\', ':' }; 238 | string text = _text.ToString(); 239 | 240 | _completionStart = text.LastIndexOfAny(anyOf); 241 | _completionStart = _completionStart == -1 ? 0 : _completionStart + 1; 242 | 243 | _completions = autoCompleteHandler.Invoke(text, _completionStart); 244 | _completions = _completions?.Length == 0 ? null : _completions; 245 | 246 | if (_completions == null) 247 | return; 248 | 249 | StartAutoComplete(); 250 | } 251 | }, 252 | 253 | ["ShiftTab"] = () => { 254 | if (IsInAutoCompleteMode()) { 255 | PreviousAutoComplete(); 256 | } 257 | } 258 | }; 259 | } 260 | public void Handle(ConsoleKeyInfo keyInfo) { 261 | _keyInfo = keyInfo; 262 | 263 | // If in auto complete mode and Tab wasn't pressed 264 | if (IsInAutoCompleteMode() && _keyInfo.Key != ConsoleKey.Tab) 265 | ResetAutoComplete(); 266 | 267 | _keyActions.TryGetValue(BuildKeyInput(), out Action action); 268 | action = action ?? WriteChar; 269 | action.Invoke(); 270 | } 271 | } 272 | internal interface IConsole { 273 | int CursorLeft { get; } 274 | int CursorTop { get; } 275 | int BufferWidth { get; } 276 | int BufferHeight { get; } 277 | void SetCursorPosition(int left, int top); 278 | void SetBufferSize(int width, int height); 279 | void Write(string value); 280 | void WriteLine(string value); 281 | } 282 | internal class Console2 : IConsole { 283 | public int CursorLeft => Console.CursorLeft; 284 | public int CursorTop => Console.CursorTop; 285 | public int BufferWidth => Console.BufferWidth; 286 | public int BufferHeight => Console.BufferHeight; 287 | public bool PasswordMode { get; set; } 288 | public void SetBufferSize(int width, int height) => Console.SetBufferSize(width, height); 289 | public void SetCursorPosition(int left, int top) { 290 | if (!PasswordMode) 291 | Console.SetCursorPosition(left, top); 292 | } 293 | public void Write(string value) { 294 | if (PasswordMode) 295 | value = new String(default(char), value.Length); 296 | Console.Write(value); 297 | } 298 | public void WriteLine(string value) => Console.WriteLine(value); 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /SWSH/SWSH.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6A30C4D1-0E4F-49B9-B2B2-D210923CE44C} 8 | Exe 9 | SWSH 10 | SWSH 11 | v4.7 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | icon.ico 37 | 38 | 39 | false 40 | 41 | 42 | 43 | ..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /SWSH/Url.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SWSH - Secure Windows Shell 3 | * Copyright (C) 2017 Muhammad Muzzammil 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | namespace SWSH { 20 | public static class Url { 21 | public const string 22 | Keygen = "https://github.com/SecureWindowsShell/swsh-keygen", 23 | Checksum = "https://raw.githubusercontent.com/SecureWindowsShell/SWSH/master/checksum", 24 | License = "https://raw.githubusercontent.com/SecureWindowsShell/SWSH/master/LICENSE"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SWSH/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SecureWindowsShell/SWSH/0624a953ed867ae658abe9a298e5bf3e4d61c65d/SWSH/icon.ico -------------------------------------------------------------------------------- /SWSH/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | image: Visual Studio 2017 3 | before_build: 4 | - cmd: nuget restore 5 | build: 6 | verbosity: minimal 7 | notifications: 8 | - provider: Email 9 | to: 10 | - swsh@muzzammil.xyz 11 | on_build_success: true 12 | on_build_failure: true 13 | on_build_status_changed: true -------------------------------------------------------------------------------- /checksum: -------------------------------------------------------------------------------- 1 | 32c2d93ae75262588a3e24d97ae9807d83bf308e 17ac506efa4c2eea4d0efeae5b9614dc3baadfaf --------------------------------------------------------------------------------