Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new feature (deny specific file extension like vsftpd) #299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ The hostname to provide a client when attempting a passive connection (`PASV`).

__Default:__ `"127.0.0.1"`

#### `deny_extension`
Deny specific file extension, if you define it, those file with not allowed to upload, rename and delete.
__Example:__ `['exe', 'dll', 'bat', 'cmd', 'vbs', 'inf', 'vbe','vbs','com', 'ws', 'reg']` will not allow users to delete , rename ,upload any files.
__Default:__ `[]`


#### `pasv_min`
Tne starting port to accept passive connections.
__Default:__ `1024`
Expand Down
9 changes: 9 additions & 0 deletions src/commands/registration/dele.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const Promise = require('bluebird');
const path = require('path');
const _ = require('lodash');

module.exports = {
directive: 'DELE',
handler: function ({log, command} = {}) {
if (!this.fs) return this.reply(550, 'File system not instantiated');
if (!this.fs.delete) return this.reply(402, 'Not supported by file system');

const fileName = command.arg;
//过滤指定文件拓展名
if (_.includes(this.server.options.deny_extension, _.lowerCase(path.extname(fileName))) ) {
return this.reply(502, 'file extension blacklisted');
}


return Promise.try(() => this.fs.delete(command.arg))
.then(() => {
return this.reply(250);
Expand Down
9 changes: 9 additions & 0 deletions src/commands/registration/rnfr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const Promise = require('bluebird');
const path = require('path');
const _ = require('lodash');


module.exports = {
directive: 'RNFR',
Expand All @@ -7,6 +10,12 @@ module.exports = {
if (!this.fs.get) return this.reply(402, 'Not supported by file system');

const fileName = command.arg;

//过滤指定文件拓展名
if (_.includes(this.server.options.deny_extension, _.lowerCase(path.extname(fileName))) ) {
return this.reply(502, 'file extension blacklisted');
}

return Promise.try(() => this.fs.get(fileName))
.then(() => {
this.renameFrom = fileName;
Expand Down
9 changes: 9 additions & 0 deletions src/commands/registration/stor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Promise = require('bluebird');
const path = require('path');
const _ = require('lodash');

module.exports = {
directive: 'STOR',
Expand All @@ -9,6 +11,13 @@ module.exports = {
const append = command.directive === 'APPE';
const fileName = command.arg;

console.log(_.lowerCase(path.extname(fileName)))
//过滤指定文件拓展名
if (_.includes(this.server.options.deny_extension, _.lowerCase(path.extname(fileName))) ) {
return this.reply(502, 'file extension blacklisted');
}


return this.connector.waitForConnection()
.tap(() => this.commandSocket.pause())
.then(() => Promise.try(() => this.fs.write(fileName, {append, start: this.restByteCount})))
Expand Down